You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Guy <gu...@gmail.com> on 2009/05/12 14:21:18 UTC

Apache Exec does not work for linux sleep command

Hi all,

I have the following problem (using Exec revision 770463):

When I start a script on a Linux machine using a java 1.6 that performs a
sleep command that is longer than the timeout specified in the WatchDog, I
get the following exception:

org.apache.commons.exec.ExecuteException: Process exited with an error:
143(Exit value: 143)
        at
org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:346)
        at
org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:149)
        at
org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:136)
        at TestApacheExec.main(TestApacheExec.java:24)

I do not get this exception when executing the code on a Windows 2003 Server
machine.

Here are all the code fragments used:

My Test Code:

public static void main(String[] args) {
        System.out.println("BEGIN " + new Date());

        try
        {
            int timeout = 10000; //10 second timeout
            System.out.println("Trying to run command: \"" + args[0] +
"\"");
            CommandLine commandLine = CommandLine.parse(args[0]);
            System.out.println("setting timeout to " + timeout + "
milliseconds.") ;
            ExecuteWatchdog watchdog = new ExecuteWatchdog(timeout);
            DefaultExecutor executor = new DefaultExecutor();
            executor.setWatchdog(watchdog);
            executor.setExitValue(1);
            System.out.println("Executing script\n");
            int exitValue = executor.execute(commandLine);
            System.out.println("\nScript executed");
            System.out.println("exitValue=" + exitValue);
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }

        System.out.println("END " + new Date());
    }



The WMI script:

WScript.Echo "staring WMI sleep" & " " & now()
WScript.Sleep(30000)
WScript.Echo "WMI sleep ended" & " " & now()

The KSH script:

date
echo "Starting ksh script"
sleep 30
echo "Ending ksh script"
date

The KSH output:

java -cp .:commons-exec-1.0.0.jar TestApacheExec "ksh testsleep"
BEGIN Tue May 12 14:19:20 CEST 2009
Trying to run command: "ksh testsleep"
setting timeout to 10000 milliseconds.
Executing script

Tue May 12 14:19:20 CEST 2009
Starting ksh script
org.apache.commons.exec.ExecuteException: Process exited with an error:
143(Exit value: 143)
        at
org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:346)
        at
org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:149)
        at
org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:136)
        at TestApacheExec.main(TestApacheExec.java:24)
END Tue May 12 14:19:50 CEST 2009

kind regards

Guy Van Tilborgh