# Stdout

**URL:** <https://www.ruby-forum.com/t/stdout/172100>\
**Category:** Ruby\
**Created:** [July 14, 2009, 8:36pm UTC](https://www.ruby-forum.com/t/stdout/172100 "2009-07-14T20:36:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![arevert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/58956e/32.png) [@arevert](https://www.ruby-forum.com/u/arevert)\
**Post date:** [July 14, 2009, 8:36pm UTC](https://www.ruby-forum.com/t/stdout/172100/1 "2009-07-14T20:36:40Z")

</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|  
system(“ruby “+scriptFolder+”/”+file) # I need this output  
}

Thanks a lot!

---

<div class="post-metadata">

**Author:** ![arevert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/58956e/32.png) [@arevert](https://www.ruby-forum.com/u/arevert)\
**Post date:** [July 14, 2009, 8:45pm UTC](https://www.ruby-forum.com/t/stdout/172100/2 "2009-07-14T20:45:17Z")

</div>

You’re looking for something like

puts “ruby #{scriptFolder}/#{file}”

---

<div class="post-metadata">

**Author:** ![arevert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/58956e/32.png) [@arevert](https://www.ruby-forum.com/u/arevert)\
**Post date:** [July 14, 2009, 9:23pm UTC](https://www.ruby-forum.com/t/stdout/172100/3 "2009-07-14T21:23:24Z")

</div>

Chris D. 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:** ![arevert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/58956e/32.png) [@arevert](https://www.ruby-forum.com/u/arevert)\
**Post date:** [July 14, 2009, 9:29pm UTC](https://www.ruby-forum.com/t/stdout/172100/4 "2009-07-14T21:29:08Z")

</div>

On Tue, Jul 14, 2009 at 1:23 PM, Agustin R.[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Chris D. 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

---

<div class="post-metadata">

**Author:** ![arevert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/58956e/32.png) [@arevert](https://www.ruby-forum.com/u/arevert)\
**Post date:** [July 14, 2009, 9:50pm UTC](https://www.ruby-forum.com/t/stdout/172100/5 "2009-07-14T21:50:54Z")

</div>

Lee Hinman wrote:

> On Tue, Jul 14, 2009 at 1:23 PM, Agustin R.[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > Chris D. 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|  
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?

---

<div class="post-metadata">

**Author:** ![arevert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/58956e/32.png) [@arevert](https://www.ruby-forum.com/u/arevert)\
**Post date:** [July 14, 2009, 10:07pm UTC](https://www.ruby-forum.com/t/stdout/172100/6 "2009-07-14T22:07:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![arevert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/58956e/32.png) [@arevert](https://www.ruby-forum.com/u/arevert)\
**Post date:** [July 14, 2009, 9:56pm UTC](https://www.ruby-forum.com/t/stdout/172100/7 "2009-07-14T21:56:37Z")

</div>

On Tue, Jul 14, 2009 at 1:50 PM, Agustin R.[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> 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

---

<div class="post-metadata">

**Author:** ![arevert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/58956e/32.png) [@arevert](https://www.ruby-forum.com/u/arevert)\
**Post date:** [July 14, 2009, 10:35pm UTC](https://www.ruby-forum.com/t/stdout/172100/8 "2009-07-14T22:35:47Z")

</div>

At 2009-07-14 03:55PM, “Lee Hinman” wrote:

> On Tue, Jul 14, 2009 at 1:50 PM, Agustin R.[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
> […]
> 
> > 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:

```
output = %x{ruby #{scriptFolder}/#{file}}

```
