Call Perl script from Ruby

N

Nick Snels

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.

Kind regards,

Nick
 
S

Steve Peters

--UlVJffcvxoiEqYs2
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Hi,
=20
I have a very basic Perl script (calls a nice CPAN library not available= =20
in Ruby) that prints it output to the screen. In Ruby I call it like:
=20
sql =3D `vendor\\sql\\sql.pl "#{@question.sql}"`
=20
But I get the following error
=20
Errno::ENOEXEC in Question#create
Exec format error - vendor\converters\sql\sql.pl "select * from=20
cdcol.cds"
=20
When I call it from DOS it works perfectly. How can I fix this? And is=20
there an alternative for using ` (backquotes)? Thanks for the help.
=20

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

ls =3D 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
(e-mail address removed)

--UlVJffcvxoiEqYs2
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.1 (GNU/Linux)

iD8DBQFEDvGz9T8SSoPkrKIRAkw/AJ9SkKq6IaFXi/x0BHtvhoLczXkPEgCeP/FJ
V0WTXwIjxYfcf6/gScHlXWM=
=wiMb
-----END PGP SIGNATURE-----

--UlVJffcvxoiEqYs2--
 
R

Robert Klemme

Nick said:
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

robert
 
L

Logan Capaldo

--Apple-Mail-28-325625152
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
delsp=yes;
format=flowed


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.


--Apple-Mail-28-325625152--
 
N

Nick Snels

It worked beautifully, thanks Robert. I'm also going to take a look at
popen, I say it used in another program and it looks promising.

Kind regards,

Nick
 
R

Rob Pitt

Slightly OTT, I accidently ran a perl script with:

ruby script.pl

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

Logan Capaldo

--Apple-Mail-33-429905240
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
format=flowed


Slightly OTT, I accidently ran a perl script with:

ruby script.pl

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

Was it

print "Hello, world!\n"

?


--Apple-Mail-33-429905240--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top