# Testing an external script

**URL:** <https://www.ruby-forum.com/t/testing-an-external-script/166812>\
**Category:** Rails\
**Created:** [April 29, 2009, 8:25pm UTC](https://www.ruby-forum.com/t/testing-an-external-script/166812 "2009-04-29T20:25:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [April 29, 2009, 8:25pm UTC](https://www.ruby-forum.com/t/testing-an-external-script/166812/1 "2009-04-29T20:25:41Z")

</div>

How does one pass a command line, including arguments, from a Ruby  
script to the shell. Specifically

some\_method("#{@script} -o #{@outfile} -f #{@format}")

I have tried Kernel.` Kernel.system, %x but have not hit on a correct  
syntax yet.

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [April 29, 2009, 11:19pm UTC](https://www.ruby-forum.com/t/testing-an-external-script/166812/2 "2009-04-29T23:19:58Z")

</div>

By “testing” you just mean “running”, right?

James B. wrote:

> How does one pass a command line, including arguments, from a Ruby  
> script to the shell. Specifically
> 
> some\_method(“#{@script} -o #{@outfile} -f #{@format}”)
> 
> I have tried Kernel.` Kernel.system, %x but have not hit on a correct  
> syntax yet.

It’s just system(“”). If your variables are valid, if your script is in  
the  
current right folder, and if your @outfile has no spaces in it, then the  
above  
should work with system(“”).

What error message do you get?

And note you can use popen() to route the output into a string in your  
program…

–  
Phlip  
[http://flea.sourceforge.net/resume.html](http://flea.sourceforge.net/resume.html)

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [April 30, 2009, 12:15am UTC](https://www.ruby-forum.com/t/testing-an-external-script/166812/3 "2009-04-30T00:15:57Z")

</div>

Phlip wrote:

> By “testing” you just mean “running”, right?

I ended up with this:

task = "ruby #{@forex\_xfr\_script} " +  
"’-f #{@forex\_outfile\_type}’ " +  
"’-o #{@forex\_outfile\_name}’ " +  
“-t”  
stdout = %x(#{task})
