Can't see ouput of executed command

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

Andi S. wrote:

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

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

Andi S. 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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs