redirecting output ruby and from stdout results in blank file

Discussion in 'Ruby' started by comp.lang.ruby, Jan 11, 2010.

  1. 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!
    comp.lang.ruby, Jan 11, 2010
    #1
    1. Advertising

  2. > 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
    Jonathan Nielsen, Jan 11, 2010
    #2
    1. Advertising

  3. 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 <>
    Iñaki Baz Castillo, Jan 11, 2010
    #3
  4. On Jan 11, 1:27 pm, Iñaki Baz Castillo <> 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 <>


    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?
    comp.lang.ruby, Jan 11, 2010
    #4
  5. comp.lang.ruby

    Gary Wright Guest

    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
    Gary Wright, Jan 11, 2010
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Douwe
    Replies:
    1
    Views:
    5,624
    Mike Schilling
    Jan 12, 2004
  2. Birch
    Replies:
    3
    Views:
    1,012
    Birch
    Oct 21, 2003
  3. Elad
    Replies:
    0
    Views:
    404
  4. =?gb2312?B?yMvR1MLkyNXKx8zs0cSjrM37vKvM7NHEsru8+7z

    Issue of redirecting the stdout to both file and screen

    =?gb2312?B?yMvR1MLkyNXKx8zs0cSjrM37vKvM7NHEsru8+7z, May 28, 2007, in forum: Python
    Replies:
    5
    Views:
    353
    =?gb2312?B?yMvR1MLkyNXKx8zs0cSjrM37vKvM7NHEsru8+7z
    May 29, 2007
  5. it_says_BALLS_on_your forehead
    Replies:
    2
    Views:
    250
    Joe Smith
    Jan 10, 2006
Loading...

Share This Page