redirecting output ruby and from stdout results in blank file

C

comp.lang.ruby

Hi all, I'm executing a program from within my ruby script and
attempting to capture the output of stderr and stdout. The relevant
lines of code are below:

def create_cmd(count)
$webkit_path + ' ' + $url + " 1>std_out.#{$options[:seed]}.#{$options
[:prefix]}.#{$count} 2>std_err.#{$options[:seed]}.#{$options
[:prefix]}.#{$count} "
end

system(create_cmd(0))

When I remove the redirection, I see all of the output that I expect.
However, when I execute the above lines, only std_err has content,
while std_out has nothing. The output being collected is standard
printfs in a modified version of WebKit, if that's relevant.

I am totally baffled how this is happening. I hope it's something
easy, my brain is waking up from vacation.

Be sure to let me know if I can provide any other relevant details to
help diagnose this problem.

Thank you!
 
J

Jonathan Nielsen

When I remove the redirection, I see all of the output that I expect.
However, when I execute the above lines, only std_err has content,
while std_out has nothing. The output being collected is standard
printfs in a modified version of WebKit, if that's relevant.

It's possible that I'm misinterpreting what you want here, but you may
want to look into the function popen3:

http://ruby-doc.org/stdlib/libdoc/open3/rdoc/index.html

It let's you specify what to do with the stdin, stdout, and stderr streams.

-Jonathan Nielsen
 
I

Iñaki Baz Castillo

El Lunes, 11 de Enero de 2010, Jonathan Nielsen escribi=F3:
=20
It's possible that I'm misinterpreting what you want here, but you may
want to look into the function popen3:
=20
http://ruby-doc.org/stdlib/libdoc/open3/rdoc/index.html
=20
It let's you specify what to do with the stdin, stdout, and stderr stream=
s.

I recommend popen4 as it also gets the correct exit status code of the=20
executed command.

=2D-=20
I=F1aki Baz Castillo <[email protected]>
 
C

comp.lang.ruby

El Lunes, 11 de Enero de 2010, Jonathan Nielsen escribió:

I recommend popen4 as it also gets the correct exit status code of the
executed command.

Thanks a lot for the suggestion. However, std_error is redirecting
fine and I have noticed that when I omit the redirection characters in
the open command, the ouput is outputted to stdout, as I expect. I am
happy to switch to popen if that's the only solution -- I just find
this to be really weird behavior. Any guesses about why this happened?
 
G

Gary Wright

=20
Thanks a lot for the suggestion. However, std_error is redirecting
fine and I have noticed that when I omit the redirection characters in
the open command, the ouput is outputted to stdout, as I expect. I am
happy to switch to popen if that's the only solution -- I just find
this to be really weird behavior. Any guesses about why this happened?

Is the standard output file being created and then is found to be empty =
or is it not being created at all?

If it isn't getting created at all, then there is something wrong with =
your command line. If it is being created but is empty, then I would =
focus on the webkit program. Things to think about:

Take a look at the constructed command line. You didn't show us that in =
your email.
Is webkit designed to behave differently when writing to the terminal =
versus a file?
Is the output being buffered when redirected to a file versus to the =
terminal?




Gary Wright
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,140
Latest member
SweetcalmCBDreview
Top