Can't see ouput of executed command

Discussion in 'Ruby' started by Andi Schacke, Feb 27, 2007.

  1. Andi Schacke

    Andi Schacke Guest

    Hi,

    On a windows system, I execute a command using the 'backtick' notation,
    but I can't see the output of the command.

    For example:

    `echo Hello` --> no output

    `mvn.bat -version` --> no output

    `date` --> no output

    When I enter these commands in irb, I can see the correct output. What
    irritates me in addition to that is that I can see the output of several
    commands, for example

    `cvs --help` --> gives me the CVS-Help-output

    Any hints?

    Thanks
    Andi

    --
    Posted via http://www.ruby-forum.com/.
    Andi Schacke, Feb 27, 2007
    #1
    1. Advertising

  2. Andi Schacke wrote:
    > Hi,
    >
    > On a windows system, I execute a command using the 'backtick' notation,
    > but I can't see the output of the command.
    >
    > For example:
    >
    > `echo Hello` --> no output
    >
    > `mvn.bat -version` --> no output
    >
    > `date` --> no output


    If you mean there's not output on your terminal while you are calling
    this from a ruby program, that is perfectly normal. The idea behind the
    backticks is that *instead* of outputting the result to the terminal,
    the generated text is the value of the expression. You do see it in irb
    because irb prints the values of the expressions it evaluates.

    Try out:

    txt = `echo stuff`
    puts "got #{txt} from echo"

    > When I enter these commands in irb, I can see the correct output. What
    > irritates me in addition to that is that I can see the output of several
    > commands, for example
    >
    > `cvs --help` --> gives me the CVS-Help-output


    This is normal, as cvs gives its help on standard error, which is not
    taken by the backticks and goes to your terminal.

    If you simply want to execute a command and see it's output in a
    terminal, use system "command" rather than the backticks.

    Cheers,

    Vince
    --
    Vincent Fourmond, PhD student (not for long anymore)
    http://vincent.fourmond.neuf.fr/
    Vincent Fourmond, Feb 27, 2007
    #2
    1. Advertising

  3. Andi Schacke

    Andi Schacke Guest

    >
    > If you simply want to execute a command and see it's output in a
    > terminal, use system "command" rather than the backticks.
    >


    Thanks a lot. So what's the difference between system() and exec()?

    Cheers Andi

    --
    Posted via http://www.ruby-forum.com/.
    Andi Schacke, Feb 27, 2007
    #3
  4. Andi Schacke wrote:
    >> If you simply want to execute a command and see it's output in a
    >> terminal, use system "command" rather than the backticks.
    >>

    >
    > Thanks a lot. So what's the difference between system() and exec()?


    system = spawns a subprogram to run something
    exec = replaces the current program by the given command.

    Unless you know what you are doing, you'll never need exec.

    Cheers,

    Vince

    --
    Vincent Fourmond, PhD student (not for long anymore)
    http://vincent.fourmond.neuf.fr/
    Vincent Fourmond, Feb 27, 2007
    #4
    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. slash

    ouput issues

    slash, Jul 22, 2003, in forum: Perl
    Replies:
    0
    Views:
    1,031
    slash
    Jul 22, 2003
  2. Flip
    Replies:
    3
    Views:
    970
    Tony Morris
    Feb 9, 2004
  3. Jp Calderone

    Re: ouput redirection..a newbie question

    Jp Calderone, Dec 15, 2003, in forum: Python
    Replies:
    2
    Views:
    298
    Lonnie Princehouse
    Dec 15, 2003
  4. Replies:
    3
    Views:
    358
  5. Dragoescu Daniel

    Assigne command ouput to a variable

    Dragoescu Daniel, Nov 7, 2007, in forum: Ruby
    Replies:
    4
    Views:
    125
Loading...

Share This Page