shell.exec hangs launching background process (windows)

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

shell.exec hangs launching background process (windows)

lukestephenon
This isn't an issue with the glu agent, more a lack of my understanding of how to execute processes in the background on windows.

I've got a long running java application which I launch on unix with:
shell.exec("java MyServer &")

I'm now trying to achieve exactly the same on windows.  I've switched to using javaw, as the application is not interactive.  
I'm launching with
shell.exec("START /B CMD /C CALL javaw MyServer")
While the application is started, the call to shell.exec never returns.  Some debugging shows the agent is waiting for the processes output stream to close.

I've also tried based on this info http://stackoverflow.com/questions/649634/how-do-i-run-a-bat-file-in-the-background-from-another-bat-file the following:
shell.exec("START /B CMD /C CALL javaw MyServer >NUL 2>&1")
shell.exec("START /B CMD /C CALL javaw MyServer ^>NUL 2^>^&1")

But so far I've failed to start the process and have the agent continue pass shell.exec

If I kill the launched java process from task manager, then the agent continues.

How hard can it be to launch a process in the background on windows?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: shell.exec hangs launching background process (windows)

frenchyan
Administrator
I have personally no idea, but I think you are right that if the process does not redirect output and error appropriately and run in the background, the exec call will block.

Yan
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: shell.exec hangs launching background process (windows)

lukestephenon
Thanks Yan.

My workaround at the moment to prevent the script from blocking is to use the following:
shell.exec(res:'stdoutStream', command: startCommand)  

Not perfect, but for now it lets me progress.  Hopefully I'll be able to post an answer soon.
Loading...