Hi folks,
I was playing with Open3.popen3 to try and manipulate some child
processes where I needed both the return code and control of stderr, but
it didn't seem to return the correct exit status. I don't know if this
is correct or not, but it seems to do what I think it should.
Maybe there's a lot of code that depends on the existing behavior, but I
think with the version in 1.8, you never get the return status of the
grandchild process. Oh, and I also cleaned up the formatting (changed
tabs to spaces).
I've attached the patch (generated by: $ diff -urN -F^f
/usr/lib/ruby/1.8/open3.rb open3.rb >/tmp/open3.patch) if anyone's
interested.
Cheers,
ast
P.S. if I don't reply immediately to any responses, I apologize in
advance. I'm having serious trouble keeping up with the list volume and
the other things I'm supposed to be doing.
open3.patch (1.67 KB)
···
***************************************************************************************************
The information in this email is confidential and may be legally privileged. Access to this email by anyone other than the intended addressee is unauthorized. If you are not the intended recipient of this message, any review, disclosure, copying, distribution, retention, or any action taken or omitted to be taken in reliance on it is prohibited and may be unlawful. If you are not the intended recipient, please reply to or forward a copy of this message to the sender and delete the message, any attachments, and any copies thereof from your system.
***************************************************************************************************
session allows you to do this - but you'll running through sh/bash like:
require 'session'
sh = Session::new
stdout, stdout = sh.exexute 'a.out'
exit_status = sh.exit_status
session is also thread safe.
another thing you might be interested in is open4, eg:
pid, stdin, stdout, stderr = Open4::popen4 'a.out'
exit_status = Process::waitpid2(cid).exitstatus
both are at
http://codeforpeople.com/lib/ruby
http://codeforpeople.com/lib/ruby/session/
http://codeforpeople.com/lib/ruby/open4/
and listed on the raa.
cheers.
-a
open3.patch (1.67 KB)
···
On Sun, 25 Sep 2005, Andrew S. Townley wrote:
Hi folks,
I was playing with Open3.popen3 to try and manipulate some child
processes where I needed both the return code and control of stderr, but
it didn't seem to return the correct exit status. I don't know if this
is correct or not, but it seems to do what I think it should.
Maybe there's a lot of code that depends on the existing behavior, but I
think with the version in 1.8, you never get the return status of the
grandchild process. Oh, and I also cleaned up the formatting (changed
tabs to spaces).
I've attached the patch (generated by: $ diff -urN -F^f
/usr/lib/ruby/1.8/open3.rb open3.rb >/tmp/open3.patch) if anyone's
interested.
--
email :: ara [dot] t [dot] howard [at] noaa [dot] gov
phone :: 303.497.6469
Your life dwells amoung the causes of death
Like a lamp standing in a strong breeze. --Nagarjuna
===============================================================================
Hi,
At Sun, 25 Sep 2005 22:16:14 +0900,
Andrew S. Townley wrote in [ruby-talk:157514]:
Maybe there's a lot of code that depends on the existing behavior, but I
think with the version in 1.8, you never get the return status of the
grandchild process. Oh, and I also cleaned up the formatting (changed
tabs to spaces).
If the child process waits the grandchild process, double-fork
is nonsense.
I'd rather think Open3 should be deprecated.
···
--
Nobu Nakada
Hi Ara,
Thanks for the pointers. I'll look a little closer into these to see if
they're a better fit than my patch. I didn't know about them (of
course, I didn't go hunting because from the Pickaxe I thought open3
would do what I needed...
I don't really want to use session because I don't need another shell
just to spawn what I'm trying to do. That'd be ksh -> ruby -> ksh ->
program which seems like more overhead than I want. From your code
snippet, Open4 is probably what I really wanted, but I still think that
it's a bug that Open3.popen3 doesn't return the status code of the
grandchild process. None of the other possible values are really of any
interest, IMHO.
Thanks again,
ast
···
On Sun, 2005-09-25 at 16:43, Ara.T.Howard wrote:
On Sun, 25 Sep 2005, Andrew S. Townley wrote:
>
> Hi folks,
>
> I was playing with Open3.popen3 to try and manipulate some child
> processes where I needed both the return code and control of stderr, but
> it didn't seem to return the correct exit status. I don't know if this
> is correct or not, but it seems to do what I think it should.
> Maybe there's a lot of code that depends on the existing behavior, but I
> think with the version in 1.8, you never get the return status of the
> grandchild process. Oh, and I also cleaned up the formatting (changed
> tabs to spaces).
>
> I've attached the patch (generated by: $ diff -urN -F^f
> /usr/lib/ruby/1.8/open3.rb open3.rb >/tmp/open3.patch) if anyone's
> interested.
session allows you to do this - but you'll running through sh/bash like:
require 'session'
sh = Session::new
stdout, stdout = sh.exexute 'a.out'
exit_status = sh.exit_status
session is also thread safe.
another thing you might be interested in is open4, eg:
pid, stdin, stdout, stderr = Open4::popen4 'a.out'
exit_status = Process::waitpid2(cid).exitstatus
both are at
http://codeforpeople.com/lib/ruby
http://codeforpeople.com/lib/ruby/session/
http://codeforpeople.com/lib/ruby/open4/
and listed on the raa.
cheers.
-a
***************************************************************************************************
The information in this email is confidential and may be legally privileged. Access to this email by anyone other than the intended addressee is unauthorized. If you are not the intended recipient of this message, any review, disclosure, copying, distribution, retention, or any action taken or omitted to be taken in reliance on it is prohibited and may be unlawful. If you are not the intended recipient, please reply to or forward a copy of this message to the sender and delete the message, any attachments, and any copies thereof from your system.
***************************************************************************************************