Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > redirecting output ruby and from stdout results in blank file

Reply
Thread Tools

redirecting output ruby and from stdout results in blank file

 
 
comp.lang.ruby
Guest
Posts: n/a
 
      01-11-2010
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
[refix]}.#{$count} 2>std_err.#{$options[:seed]}.#{$options
[refix]}.#{$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!
 
Reply With Quote
 
 
 
 
Jonathan Nielsen
Guest
Posts: n/a
 
      01-11-2010
> 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

 
Reply With Quote
 
 
 
 
Iñaki Baz Castillo
Guest
Posts: n/a
 
      01-11-2010
El Lunes, 11 de Enero de 2010, Jonathan Nielsen escribi=F3:
> > 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.

>=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 <>

 
Reply With Quote
 
comp.lang.ruby
Guest
Posts: n/a
 
      01-11-2010
On Jan 11, 1:27*pm, Iñaki Baz Castillo <i...@aliax.net> wrote:
> El Lunes, 11 de Enero de 2010, Jonathan Nielsen escribió:
> > 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.

>
> I recommend popen4 as it also gets the correct exit status code of the
> executed command.
>
> --
> Iñaki Baz Castillo <i...@aliax.net>


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?
 
Reply With Quote
 
Gary Wright
Guest
Posts: n/a
 
      01-11-2010

On Jan 11, 2010, at 5:05 PM, comp.lang.ruby wrote:
>=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




 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Issue of redirecting the stdout to both file and screen =?gb2312?B?yMvR1MLkyNXKx8zs0cSjrM37vKvM7NHEsru8+7zS?= Python 5 05-29-2007 02:12 AM
Problems redirecting STDOUT (NOT sys.stdout) to a pipe. Elad Python 0 03-19-2006 01:30 PM
script hangs when run from command line and redirecting stdout and stderr to file it_says_BALLS_on_your forehead Perl Misc 2 01-10-2006 11:31 AM
Ant redirecting stdout to a file while in a spawned java program Douwe Java 1 01-12-2004 02:16 AM
stdout funniness from os.system() calls when redirecting output Birch Python 3 10-21-2003 04:16 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57