You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Stuart Broad <tr...@googlemail.com> on 2012/09/25 19:46:20 UTC

[EXEC] Shell nohup

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);
    
...

I'm running on Mac OS X 10.7.4 with Java 1.6.0_35.

Any help would be appreciated. *8-)

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [EXEC] Shell nohup

Posted by Alex P <st...@gmail.com>.
Kind of late response, but if it help anybody.
What worked for me is (in your terms):
-------------------------------------------------------
cl.addArgument("nohup ping -c 20 localhost > /dev/null 2>&1 &", false);
-------------------------------------------------------

WBR
   AlexP.


On Tue, Sep 25, 2012 at 1:46 PM, Stuart Broad <tr...@googlemail.com>wrote:

> 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);
>     ...
>
> I'm running on Mac OS X 10.7.4 with Java 1.6.0_35.
>
> Any help would be appreciated. *8-)
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>