views:

175

answers:

2

I have a small HTTP server script I've written using eventmachine which needs to call external scripts/commands and does so via backticks (``). When serving up requests which don't run backticked code, everything is fine, however, as soon as my EM code executes any backticked external script, it stops serving requests and stops executing in general.

I noticed eventmachine seems to be sensitive to sub-processes and/or threads, and appears to have the popen method for this purpose, but EM's source warns that this method doesn't work under Windows. Many of the machines running this script are running Windows, so I can't use popen.

Am I out of luck here? Is there a safe way to run an external command from an eventmachine script under Windows? Is there any way I could fire off some commands to be run externally without blocking EM's execution?

edit: the culprit that seems to be screwing up EM the most is my usage of the Windows start command, as in: start java myclass. The reason I'm using start is because I want those external scripts to start running and keep running after the EM request is served

+1  A: 

The ruby documentation states that the backtick operator "Returns the standard output of running cmd in a subshell"

So if your command i.e. start java myclass is continuing to run then ruby is waiting for it to finish to pass back it's output to your program.

Steve Weet
+1  A: 

Try win32-open3 (and if it needs to be cross-platform not windows-only, also have a look at POpen4)

gerrit