# Can't see ouput of executed command

**URL:** <https://www.ruby-forum.com/t/cant-see-ouput-of-executed-command/87021>\
**Category:** Ruby\
**Created:** [February 27, 2007, 5:55pm UTC](https://www.ruby-forum.com/t/cant-see-ouput-of-executed-command/87021 "2007-02-27T17:55:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![schacke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6a8cbe/32.png) [@schacke](https://www.ruby-forum.com/u/schacke)\
**Post date:** [February 27, 2007, 5:55pm UTC](https://www.ruby-forum.com/t/cant-see-ouput-of-executed-command/87021/1 "2007-02-27T17:55:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![schacke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6a8cbe/32.png) [@schacke](https://www.ruby-forum.com/u/schacke)\
**Post date:** [February 27, 2007, 6:01pm UTC](https://www.ruby-forum.com/t/cant-see-ouput-of-executed-command/87021/2 "2007-02-27T18:01:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![schacke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6a8cbe/32.png) [@schacke](https://www.ruby-forum.com/u/schacke)\
**Post date:** [February 27, 2007, 6:10pm UTC](https://www.ruby-forum.com/t/cant-see-ouput-of-executed-command/87021/3 "2007-02-27T18:10:26Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![schacke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6a8cbe/32.png) [@schacke](https://www.ruby-forum.com/u/schacke)\
**Post date:** [February 27, 2007, 6:13pm UTC](https://www.ruby-forum.com/t/cant-see-ouput-of-executed-command/87021/4 "2007-02-27T18:13:41Z")

</div>

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
