Ruby, Windows XP, and CMD.exe

Hello all,

I am developing a SOAP server running on a Windows XP machine. When
contacted from the outside, it will launch a windows executable at the
command line. The problem is this executable takes a long time. When I
would block on the SOAP call I would get a time out error on the client
end, as one would expect.

So when I put the command in a thread it would still cause a timeout
even though it would pass the point of executing the command line app.
It still seems that the method inside the SOAP::RPC::StandaloneServer
blocks until all the threads clear.

I’ve also tried using the windows “start” command to kick this thing
off. But again, the method blocks until the windows app finishes.

I also tried using exec(“my_app.exe”) if fork.nil? In that case the
SOAP meothd returns to the client but the windows app is prematurely cut
off before finishing.

Essentially, I need something along the lines of “command &” from unix
for windows. Any ideas?

Thanks in advance,
Snowdall

Which one send you ‘time out error’? IIS Server ? or Another?

If You use IIS, try to chang option of IIS.

2006/12/12, Clark S. [email protected]:

On Tue, 12 Dec 2006, Clark S. wrote:

It still seems that the method inside the SOAP::RPC::StandaloneServer
for windows. Any ideas?

Thanks in advance,
Snowdall

require ‘rubygems’
require ‘systemu’ # gem install systemu

cmd = ‘your.app’

t = Thread.new{ systemu cmd } # run in background

stuff

status, stdout, stderr = t.value # get info later iff needed

regards.

-a

On Wed, 13 Dec 2006, David V. wrote:

Clark S. wrote:

I am developing a SOAP server running on a Windows XP machine. When
contacted from the outside, it will launch a windows executable at the
command line. The problem is this executable takes a long time. When I
would block on the SOAP call I would get a time out error on the client
end, as one would expect.

How are you launching that process?

system() or `` are Bad Ideas, IO.popen should do what you need.

why would say that? IO.popen and more than one thread is a disaster on
windows: if the parent doesn’t read from the process fast enough one
will end
up with deadlock.

regards.

-a

Clark S. wrote:

I am developing a SOAP server running on a Windows XP machine. When
contacted from the outside, it will launch a windows executable at the
command line. The problem is this executable takes a long time. When I
would block on the SOAP call I would get a time out error on the client
end, as one would expect.

How are you launching that process?

system() or `` are Bad Ideas, IO.popen should do what you need.

David V.

Essentially, I need something along the lines of “command &” from unix
for windows. Any ideas?

Perl’s “system” function has an undocumented feature that allows you to
call:

system(1, “command”);

And the command is run “detached” - in a separate process. Under the
hood, the Win32 CreateProcess function is used. Maybe Ruby’s “system”
borrowed the feature ?

Also, Perl’s Win32::Process module allows to do it more directly. It
also calls CreateProcess under the hood, and you need to provide the
CREATE_NEW_PROCESS_GROUP flag to it in order to “detach”. Perhaps
Ruby’s equivalent module can be used.

Sorry for the Perl-talk, I’m still not too proficient with Ruby
libraries. Hope this helps, though

why would say that? IO.popen and more than one thread is a disaster on
windows: if the parent doesn’t read from the process fast enough one
will end
up with deadlock.

regards.

-a

IO.popen wins! I tried the systemu first and yes that would return, but
it never actually launched my app. In fact when I made cmd = ‘cmd.exe’
it didn’t even launch it. I also tried it with cmd = 'START my_app.exe"
but that also didn’t work.

But once I tried IO.popen that worked out of the box. Thanks to all who
helped out on this one.

Snowdall

[email protected] wrote:

How are you launching that process?

system() or `` are Bad Ideas, IO.popen should do what you need.

why would say that? IO.popen and more than one thread is a disaster on
windows: if the parent doesn’t read from the process fast enough one
will end
up with deadlock.

I made (unconsciously) a guess that it’s a fire-and-forget subprocess,
the simpler case why it would be necessary that it doesn’t block the
parent. Seems (from the later followup) I guessed right, but thanks for
bringing that point up for cases when it isn’t, I’m admittedly flaky
when it comes to process synchronisation.

David V.