# Stdout

**URL:** https://rubytalk.org/t/stdout/54412
**Category:** ruby-talk
**Created:** [14 July 2009 18:36 UTC](https://rubytalk.org/t/stdout/54412 "2009-07-14T18:36:42Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Agustin\_Ramos2](https://avatars.discourse-cdn.com/v4/letter/a/73ab20/32.png) [@Agustin\_Ramos2](https://rubytalk.org/u/Agustin_Ramos2)
#### Post date: [14 July 2009 18:36 UTC](https://rubytalk.org/t/stdout/54412/1 "2009-07-14T18:36:42Z")

</div>

Hi! I'm developing an application, that needs to execute some ruby  
files, and log the output in a txt file.  
The problem that i have is that i can't take this output.

Here is a piece of code:

filesToExec.each { |file|  
&nbsp;&nbsp;system("ruby "+scriptFolder+"/"+file) # I need this output  
}

Thanks a lot!

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

### Author: ![Chris\_Dempsey](https://avatars.discourse-cdn.com/v4/letter/c/4491bb/32.png) [@Chris\_Dempsey](https://rubytalk.org/u/Chris_Dempsey)
#### Post date: [14 July 2009 18:44 UTC](https://rubytalk.org/t/stdout/54412/2 "2009-07-14T18:44:27Z")

</div>

You're looking for something like

puts "ruby #{scriptFolder}/#{file}"

> **···**
>
> On Tue, Jul 14, 2009 at 1:36 PM, Agustin Ramos \<agus\_85@hotmail.com\> wrote:
> 
> > Hi! I'm developing an application, that needs to execute some ruby  
> > files, and log the output in a txt file.  
> > The problem that i have is that i can't take this output.
> > 
> > Here is a piece of code:
> > 
> > filesToExec.each { |file|  
> > system("ruby "+scriptFolder+"/"+file) # I need this output  
> > }
> > 
> > Thanks a lot!  
> > --  
> > Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

### Author: ![Agustin\_Ramos2](https://avatars.discourse-cdn.com/v4/letter/a/73ab20/32.png) [@Agustin\_Ramos2](https://rubytalk.org/u/Agustin_Ramos2)
#### Post date: [14 July 2009 19:23 UTC](https://rubytalk.org/t/stdout/54412/3 "2009-07-14T19:23:26Z")

</div>

Chris Dempsey wrote:

> You're looking for something like
> 
> puts "ruby #{scriptFolder}/#{file}"

Nono, the scripts that i'm running print in the screen "Testo Ok" or  
"Test Fail"  
i need to save these output in a TXT file.

Thanks!!

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

### Author: ![Lee\_Hinman](https://avatars.discourse-cdn.com/v4/letter/l/ce73a5/32.png) [@Lee\_Hinman](https://rubytalk.org/u/Lee_Hinman)
#### Post date: [14 July 2009 19:28 UTC](https://rubytalk.org/t/stdout/54412/4 "2009-07-14T19:28:26Z")

</div>

If you only need to save a single line, you can do this:

results = `ruby #{scriptFolder}/#{file}`

If you need to be looking at multiple lines, you should check out IO.popen

- Lee

> **···**
>
> On Tue, Jul 14, 2009 at 1:23 PM, Agustin Ramos\<agus\_85@hotmail.com\> wrote:
> 
> > Chris Dempsey wrote:
> > 
> > > You're looking for something like
> > > 
> > > puts "ruby #{scriptFolder}/#{file}"
> > 
> > Nono, the scripts that i'm running print in the screen "Testo Ok" or  
> > "Test Fail"  
> > i need to save these output in a TXT file.
> > 
> > Thanks!!

---

<div class="post-metadata">

### Author: ![Agustin\_Ramos2](https://avatars.discourse-cdn.com/v4/letter/a/73ab20/32.png) [@Agustin\_Ramos2](https://rubytalk.org/u/Agustin_Ramos2)
#### Post date: [14 July 2009 19:50 UTC](https://rubytalk.org/t/stdout/54412/5 "2009-07-14T19:50:56Z")

</div>

Lee Hinman wrote:

> > Chris Dempsey wrote:
> > 
> > > You're looking for something like
> > > 
> > > puts "ruby #{scriptFolder}/#{file}"
> > 
> > Nono, the scripts that i'm running print in the screen "Testo Ok" or  
> > "Test Fail"  
> > i need to save these output in a TXT file.
> > 
> > Thanks!!
> 
> If you only need to save a single line, you can do this:
> 
> results = `ruby #{scriptFolder}/#{file}`
> 
> If you need to be looking at multiple lines, you should check out  
> IO.popen
> 
> - Lee

With this line results = `ruby #{scriptFolder}/#{file}` i'm saving only  
the file location string. It's the same as  
results = "ruby "+scriptFoler+"/"+file  
You only change the concatantio symbol by printing variables into the  
string.

I need to save the cmd output, the output of the script.

So  
With this  
filesToExec.each { |file|  
&nbsp;&nbsp;system("ruby "+scriptFolder+"/"+file) # I need this output  
}  
I'm running the scripts, that's correct? or i have to do it in other  
way?

> **···**
>
> > On Tue, Jul 14, 2009 at 1:23 PM, Agustin Ramos\<agus\_85@hotmail.com\> \> wrote:
> 
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

### Author: ![Lee\_Hinman](https://avatars.discourse-cdn.com/v4/letter/l/ce73a5/32.png) [@Lee\_Hinman](https://rubytalk.org/u/Lee_Hinman)
#### Post date: [14 July 2009 19:55 UTC](https://rubytalk.org/t/stdout/54412/6 "2009-07-14T19:55:18Z")

</div>

> You only change the concatantio symbol by printing variables into the  
> string.
> 
> I need to save the cmd output, the output of the script.
> 
> So  
> With this  
> filesToExec.each { |file|  
> system("ruby "+scriptFolder+"/"+file) # I need this output  
> }  
> I'm running the scripts, that's correct? or i have to do it in other  
> way?

Using ` instead of " executes the command and returns a string of the output.

Try this in irb:

> > r = `echo "hi"`  
> > puts r

and r should equal "hi\n"

- Lee

> **···**
>
> On Tue, Jul 14, 2009 at 1:50 PM, Agustin Ramos\<agus\_85@hotmail.com\> wrote:

---

<div class="post-metadata">

### Author: ![Jim\_Xu](https://avatars.discourse-cdn.com/v4/letter/j/d2c977/32.png) [@Jim\_Xu](https://rubytalk.org/u/Jim_Xu)
#### Post date: [14 July 2009 20:07 UTC](https://rubytalk.org/t/stdout/54412/7 "2009-07-14T20:07:42Z")

</div>

NO, its a back tick, not a quote. Look carefully.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

### Author: ![Glenn\_Jackman](https://avatars.discourse-cdn.com/v4/letter/g/ce73a5/32.png) [@Glenn\_Jackman](https://rubytalk.org/u/Glenn_Jackman)
#### Post date: [14 July 2009 20:35 UTC](https://rubytalk.org/t/stdout/54412/8 "2009-07-14T20:35:10Z")

</div>

[...]

> \> system("ruby "+scriptFolder+"/"+file) # I need this output

[...]

> \> I'm running the scripts, that's correct? or i have to do it in other  
> \> way?
> 
> Using ` instead of " executes the command and returns a string of the  
> output.

Or use %x{} to stand out visually:

&nbsp;&nbsp;&nbsp;&nbsp;output = %x{ruby #{scriptFolder}/#{file}}

> **···**
>
> At 2009-07-14 03:55PM, "Lee Hinman" wrote:
> 
> > On Tue, Jul 14, 2009 at 1:50 PM, Agustin Ramos\<agus\_85@hotmail.com\> wrote:
> 
> --  
> Glenn Jackman  
> &nbsp;&nbsp;&nbsp;&nbsp;Write a wise saying and your name will live forever. -- Anonymous
