Question

By using Apache Commons-Exec I can start a program successfully, however the starter program suspended after the program started.

May I ask how to start a program and exit immediately so it will not block the following execution?

DefaultExecutor executor = new DefaultExecutor();
executor.execute( "cmd /c start C:\\Users\\xx\\program.exe");

I'm on Win7 64bit.

Thanks

Was it helpful?

Solution

According to documentation, execute(CommandLine) starts synchronous execution. That is, it blocks the calling thread. You probably want asynchronous execution, so use execute(CommandLine command, ExecuteResultHandler handler). For example,

DefaultExecutor executor = new DefaultExecutor();
executor.execute(new CommadLine("cmd /c start C:\\Users\\xx\\program.exe"),
                 new DefaultExecuteResultHandler());

OTHER TIPS

Sounds like you need to use a DefaultExecuteResultHandler.

See the tutorial (bottom of) for more info.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top