# Call Perl script from Ruby

**URL:** <https://rubytalk.org/t/call-perl-script-from-ruby/25553>\
**Category:** ruby-talk\
**Created:** [8 March 2006 14:00 UTC](https://rubytalk.org/t/call-perl-script-from-ruby/25553 "2006-03-08T14:00:42Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nick\_Snels](https://avatars.discourse-cdn.com/v4/letter/n/bc79bd/32.png) [@Nick\_Snels](https://rubytalk.org/u/Nick_Snels)\
**Post date:** [8 March 2006 14:00 UTC](https://rubytalk.org/t/call-perl-script-from-ruby/25553/1 "2006-03-08T14:00:42Z")

</div>

Hi,

I have a very basic Perl script (calls a nice CPAN library not available  
in Ruby) that prints it output to the screen. In Ruby I call it like:

sql = `vendor\\sql\\[sql.pl](http://sql.pl) "#{@question.sql}"`

But I get the following error

Errno::ENOEXEC in Question#create  
Exec format error - vendor\converters\sql\[sql.pl](http://sql.pl) "select \* from  
cdcol.cds"

When I call it from DOS it works perfectly. How can I fix this? And is  
there an alternative for using ` (backquotes)? Thanks for the help.

Kind regards,

Nick

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

---

<div class="post-metadata">

**Author:** ![Steve\_Peters](https://avatars.discourse-cdn.com/v4/letter/s/dbc845/32.png) [@Steve\_Peters](https://rubytalk.org/u/Steve_Peters)\
**Post date:** [8 March 2006 15:01 UTC](https://rubytalk.org/t/call-perl-script-from-ruby/25553/2 "2006-03-08T15:01:01Z")

</div>

IO.popen is one way to go. Here's a quick example...

ls = IO.popen("ls -ltr", "r")  
puts ls.readlines

Kernel.exec should be the same as using the backquotes. If you need  
something more robust, take a look at Open3.

Steve Peters  
steve@fisharerojo.org

> **···**
>
> On Wed, Mar 08, 2006 at 11:00:42PM +0900, Nick Snels wrote:
> 
> > Hi,
> > 
> > I have a very basic Perl script (calls a nice CPAN library not available  
> > in Ruby) that prints it output to the screen. In Ruby I call it like:
> > 
> > sql = `vendor\\sql\\sql.pl "#{@question.sql}"`
> > 
> > But I get the following error
> > 
> > Errno::ENOEXEC in Question#create  
> > Exec format error - vendor\converters\sql\sql.pl "select \* from  
> > cdcol.cds"
> > 
> > When I call it from DOS it works perfectly. How can I fix this? And is  
> > there an alternative for using ` (backquotes)? Thanks for the help.

---

<div class="post-metadata">

**Author:** ![Robert](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@Robert](https://rubytalk.org/u/Robert)\
**Post date:** [8 March 2006 15:18 UTC](https://rubytalk.org/t/call-perl-script-from-ruby/25553/3 "2006-03-08T15:18:41Z")

</div>

Nick Snels wrote:

> Hi,
> 
> I have a very basic Perl script (calls a nice CPAN library not  
> available in Ruby) that prints it output to the screen. In Ruby I  
> call it like:
> 
> sql = `vendor\\sql\\sql.pl "#{@question.sql}"`
> 
> But I get the following error
> 
> Errno::ENOEXEC in Question#create  
> Exec format error - vendor\converters\sql\sql.pl "select \* from  
> cdcol.cds"

try this:

sql = `perl vendor\\sql\\sql.pl "#{@question.sql}"`

Regards

&nbsp;&nbsp;&nbsp;&nbsp;robert

---

<div class="post-metadata">

**Author:** ![Hiep\_Nguyen](https://avatars.discourse-cdn.com/v4/letter/h/8e8cbc/32.png) [@Hiep\_Nguyen](https://rubytalk.org/u/Hiep_Nguyen)\
**Post date:** [2 November 2011 08:31 UTC](https://rubytalk.org/t/call-perl-script-from-ruby/25553/4 "2011-11-02T08:31:34Z")

</div>

Hello Robert,

I am newbe, and I get in trouble with special character '-\>'  
e.g :

use Test::WWW::Mechanize;  
my $mech = Test::WWW::Mechanize-\>new( );  
$mech-\>get\_ok( '[http://search.cpan.org/](http://search.cpan.org/)' );

How can we deal with this character.

your help is very appriciated

Hiep

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

---

<div class="post-metadata">

**Author:** ![Hiep\_Nguyen](https://avatars.discourse-cdn.com/v4/letter/h/8e8cbc/32.png) [@Hiep\_Nguyen](https://rubytalk.org/u/Hiep_Nguyen)\
**Post date:** [2 November 2011 08:44 UTC](https://rubytalk.org/t/call-perl-script-from-ruby/25553/5 "2011-11-02T08:44:03Z")

</div>

I use  
\<\<perl [script.pl](http://script.pl)\>\> instead \<\<ruby [script.pl](http://script.pl)\>\>

and it works  
BTW Thanks you

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

---

<div class="post-metadata">

**Author:** ![Logan\_Capaldo](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@Logan\_Capaldo](https://rubytalk.org/u/Logan_Capaldo)\
**Post date:** [8 March 2006 18:13 UTC](https://rubytalk.org/t/call-perl-script-from-ruby/25553/6 "2006-03-08T18:13:23Z")

</div>

Eeek! It is certainly not the same as using backquotes. exec \_replaces\_ the currently running process with its argument, he'd never return to ruby to do additional processing.

> **···**
>
> On Mar 8, 2006, at 10:01 AM, Steve Peters wrote:
> 
> > Kernel.exec should be the same as using the backquotes

---

<div class="post-metadata">

**Author:** ![Rob\_Pitt1](https://avatars.discourse-cdn.com/v4/letter/r/e495f1/32.png) [@Rob\_Pitt1](https://rubytalk.org/u/Rob_Pitt1)\
**Post date:** [9 March 2006 09:27 UTC](https://rubytalk.org/t/call-perl-script-from-ruby/25553/7 "2006-03-09T09:27:44Z")

</div>

Slightly OTT, I accidently ran a perl script with:

ruby script.pl

The other day, and it executed fine!!!!

> **···**
>
> On 8 Mar 2006, at 18:13, Logan Capaldo wrote:
> 
> > On Mar 8, 2006, at 10:01 AM, Steve Peters wrote:
> > 
> > > Kernel.exec should be the same as using the backquotes
> > 
> > Eeek! It is certainly not the same as using backquotes. exec \_replaces\_ the currently running process with its argument, he'd never return to ruby to do additional processing.

---

<div class="post-metadata">

**Author:** ![Rob\_Pitt1](https://avatars.discourse-cdn.com/v4/letter/r/e495f1/32.png) [@Rob\_Pitt1](https://rubytalk.org/u/Rob_Pitt1)\
**Post date:** [9 March 2006 09:28 UTC](https://rubytalk.org/t/call-perl-script-from-ruby/25553/8 "2006-03-09T09:28:02Z")

</div>

Look at them gem called "session". It's nice for executing processes.

> **···**
>
> On 8 Mar 2006, at 18:13, Logan Capaldo wrote:
> 
> > On Mar 8, 2006, at 10:01 AM, Steve Peters wrote:
> > 
> > > Kernel.exec should be the same as using the backquotes
> > 
> > Eeek! It is certainly not the same as using backquotes. exec \_replaces\_ the currently running process with its argument, he'd never return to ruby to do additional processing.

---

<div class="post-metadata">

**Author:** ![Logan\_Capaldo](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@Logan\_Capaldo](https://rubytalk.org/u/Logan_Capaldo)\
**Post date:** [9 March 2006 23:11 UTC](https://rubytalk.org/t/call-perl-script-from-ruby/25553/9 "2006-03-09T23:11:21Z")

</div>

Was it

print "Hello, world!\n"

?

> **···**
>
> On Mar 9, 2006, at 4:27 AM, Rob Pitt wrote:
> 
> > Slightly OTT, I accidently ran a perl script with:
> > 
> > ruby script.pl
> > 
> > The other day, and it executed fine!!!!
