Can't see ouput of executed command

A

Andi Schacke

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
 
V

Vincent Fourmond

Andi said:
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
 
A

Andi Schacke

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
 
V

Vincent Fourmond

Andi said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top