# Ruby, Windows XP, and CMD.exe

**URL:** <https://www.ruby-forum.com/t/ruby-windows-xp-and-cmd-exe/79092>\
**Category:** Ruby\
**Created:** [December 12, 2006, 2:11am UTC](https://www.ruby-forum.com/t/ruby-windows-xp-and-cmd-exe/79092 "2006-12-12T02:11:14Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![snowdall](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/45deac/32.png) [@snowdall](https://www.ruby-forum.com/u/snowdall)\
**Post date:** [December 12, 2006, 2:11am UTC](https://www.ruby-forum.com/t/ruby-windows-xp-and-cmd-exe/79092/1 "2006-12-12T02:11:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![snowdall](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/45deac/32.png) [@snowdall](https://www.ruby-forum.com/u/snowdall)\
**Post date:** [December 12, 2006, 2:46am UTC](https://www.ruby-forum.com/t/ruby-windows-xp-and-cmd-exe/79092/2 "2006-12-12T02:46:59Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![snowdall](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/45deac/32.png) [@snowdall](https://www.ruby-forum.com/u/snowdall)\
**Post date:** [December 12, 2006, 8:03am UTC](https://www.ruby-forum.com/t/ruby-windows-xp-and-cmd-exe/79092/3 "2006-12-12T08:03:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![snowdall](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/45deac/32.png) [@snowdall](https://www.ruby-forum.com/u/snowdall)\
**Post date:** [December 12, 2006, 10:28pm UTC](https://www.ruby-forum.com/t/ruby-windows-xp-and-cmd-exe/79092/4 "2006-12-12T22:28:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![snowdall](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/45deac/32.png) [@snowdall](https://www.ruby-forum.com/u/snowdall)\
**Post date:** [December 12, 2006, 10:02pm UTC](https://www.ruby-forum.com/t/ruby-windows-xp-and-cmd-exe/79092/5 "2006-12-12T22:02:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![snowdall](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/45deac/32.png) [@snowdall](https://www.ruby-forum.com/u/snowdall)\
**Post date:** [December 13, 2006, 4:45am UTC](https://www.ruby-forum.com/t/ruby-windows-xp-and-cmd-exe/79092/6 "2006-12-13T04:45:36Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![snowdall](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/45deac/32.png) [@snowdall](https://www.ruby-forum.com/u/snowdall)\
**Post date:** [December 13, 2006, 7:52pm UTC](https://www.ruby-forum.com/t/ruby-windows-xp-and-cmd-exe/79092/7 "2006-12-13T19:52:25Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![snowdall](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/45deac/32.png) [@snowdall](https://www.ruby-forum.com/u/snowdall)\
**Post date:** [December 13, 2006, 8:33pm UTC](https://www.ruby-forum.com/t/ruby-windows-xp-and-cmd-exe/79092/8 "2006-12-13T20:33:21Z")

</div>

removed\_email\_address@domain.invalid 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.
