# Run perl script and capture the output

**URL:** <https://www.ruby-forum.com/t/run-perl-script-and-capture-the-output/79879>\
**Category:** Ruby\
**Created:** [December 20, 2006, 5:24am UTC](https://www.ruby-forum.com/t/run-perl-script-and-capture-the-output/79879 "2006-12-20T05:24:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex-osu3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@alex-osu3](https://www.ruby-forum.com/u/alex-osu3)\
**Post date:** [December 20, 2006, 5:24am UTC](https://www.ruby-forum.com/t/run-perl-script-and-capture-the-output/79879/1 "2006-12-20T05:24:59Z")

</div>

Hi all,

I need to run a perl script from Ruby and capture its output. I use the  
following line in Ruby but it fails. Any input will be appreciated.

out=`perl c:\\Perl\\self\\back1\.pl`

Li

---

<div class="post-metadata">

**Author:** ![alex-osu3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@alex-osu3](https://www.ruby-forum.com/u/alex-osu3)\
**Post date:** [December 20, 2006, 7:29pm UTC](https://www.ruby-forum.com/t/run-perl-script-and-capture-the-output/79879/2 "2006-12-20T19:29:07Z")

</div>

maybe you can try to use an absolute path to ‘perl’.

2006/12/20, Li Chen [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![alex-osu3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@alex-osu3](https://www.ruby-forum.com/u/alex-osu3)\
**Post date:** [December 20, 2006, 7:37pm UTC](https://www.ruby-forum.com/t/run-perl-script-and-capture-the-output/79879/3 "2006-12-20T19:37:10Z")

</div>

Li Chen wrote:

> Hi all,
> 
> I need to run a perl script from Ruby and capture its output. I use the  
> following line in Ruby but it fails.

Define “fails”. What happened?

> Any input will be appreciated.
> 
> out=`perl c:\\Perl\\self\\back1\.pl`

Is this really the line you used? How about this instead:

out=`perl c:\\Perl\\self\\back1.pl`

Or, because I have no way to test your Windows syntax:

out=`perl c:/Perl/self/back1.pl`

Also, if Perl has been installed correctly and the Perl script is  
written  
reasonably well, you shouldn’t need the “perl” command in the line.

If these alternatives fail, you will have to run some tests, and work up  
to  
the script.

Tests like this:

out = `perl -v`

See what this puts in the “out” variable.
