Uploaded image for project: 'Commons Exec'
  1. Commons Exec
  2. EXEC-67

Shell (-c) command execution - fire and forget

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Invalid
    • 1.1
    • None
    • OS: Mac OS X 10.7.4
      Java version: "1.6.0_35"

    Description

      I am attempting to 'fire and forget' a process. Using java ProcessBuilder I can do this as follows:

      ProcessBuilder pb = new ProcessBuilder("sh", "-c", "nohup ping -c 20 localhost > /dev/null 2>&1 &");
      ...

      Running using Commons Exec I get the following error:

      sh: nohup ping -c 20 localhost > /dev/null 2>&1 &: No such file or directory

      The stripped down code is as follows:

      ...
      DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
      PumpStreamHandler psh = new PumpStreamHandler(logHandler);
      CommandLine cl = CommandLine.parse("sh");
      cl.addArgument("-c");
      cl.addArgument("nohup ping -c 20 localhost > /dev/null 2>&1 &");
      DefaultExecutor exec = new DefaultExecutor();
      mWatchDog = new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT);
      exec.setStreamHandler(psh);
      exec.setWatchdog(mWatchDog);
      exec.execute(cl, resultHandler);
      ...

      Attachments

        Activity

          People

            Unassigned Unassigned
            trisport88 Stuart Broad
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: