Hi all,
What is the easiest (or any) way to do the following with Ruby on
Windows:
- execute a child process
- get the output written to stdout and stderr (as with
<command>
)
- also get the exit code ($?)
- in a thread safe way
On unix I would probably revert to using a pipe, fork and waitpid2.
However, fork does not seem to be available (understandably) on Windows.
Any other options I missed?
Is $? thread safe?
Ronald.
Ronald Pijnacker wrote:
What is the easiest (or any) way to do the following with Ruby on
Windows:
- execute a child process
- get the output written to stdout and stderr (as with
<command>
)
- also get the exit code ($?)
- in a thread safe way
Can’t answer all your questions, but I’ll share what I got.
First, see http://ruby-talk.com/10006 for some replacement methods for
`` and system, if you’re unable to get the originals to work on Windows.
Downside as this post mentions (http://ruby-talk.com/blade/41583) is
that $? is then not set. It also doesn’t help you with stderr, although
there was a recent thread with making a popen3 for Windows, dunno what
the latest on that is. And thread-safe - dunno either.
···
–
Chris
http://clabs.org/blogki
-=-=-=-=-=-=-=-=-=-=-=-=-=-
Free solo piano album (mp3)
http://cministries.org/cstudios/blackandwhite.htm
Hi,
- execute a child process
- get the output written to stdout and stderr (as with
<command>
)
- also get the exit code ($?)
- in a thread safe way
If you run on NT,
IO.popen(“your-command 2>&1”) {|f|
output = f.read
exitcode = Process.waitpid2(f.pid)[1]
}
On unix I would probably revert to using a pipe, fork and waitpid2.
However, fork does not seem to be available (understandably) on Windows.
Any other options I missed?
I’d like to add arguments specifying redirection to system,
popen etc. for portability, but don’t have nice notation yet.
Is $? thread safe?
Yes. $? is a thread local variable.
···
At Tue, 15 Jul 2003 17:46:31 +0900, Ronald Pijnacker wrote:
–
Nobu Nakada
Hi,
- execute a child process
- get the output written to stdout and stderr (as with
<command>
)
- also get the exit code ($?)
- in a thread safe way
If you run on NT,
IO.popen(“your-command 2>&1”) {|f|
output = f.read
exitcode = Process.waitpid2(f.pid)[1]
}
On unix I would probably revert to using a pipe, fork and waitpid2.
However, fork does not seem to be available (understandably) on Windows.
Any other options I missed?
I’d like to add arguments specifying redirection to system,
popen etc. for portability, but don’t have nice notation yet.
Is $? thread safe?
Yes. $? is a thread local variable.
Thanks! This was just what I was looking for. I wonder why I missed
this in the documentation. The f.pid part supprised me a bit though…
Ronald.
···
At Tue, 15 Jul 2003 17:46:31 +0900, > Ronald Pijnacker wrote: