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!
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 N.
El Lunes, 11 de Enero de 2010, Jonathan N.
escribió:> It let’s you specify what to do with the stdin, stdout, and stderr streams.
I recommend popen4 as it also gets the correct exit status code of the
executed command.
On Jan 11, 1:27 pm, Iñaki Baz C. [email protected] wrote:
–
Iñaki Baz C. [email protected]
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?
On Jan 11, 2010, at 5:05 PM, comp.lang.ruby wrote:
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 W.