Forum: Ruby Call Perl script from Ruby

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
91308e9bc88cb069fd1bcf88e910d042?d=identicon&s=25 Nick Snels (nicksnels)
on 2006-03-08 15:00
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
46a8fffa03e75f278c57ac37f11c07e2?d=identicon&s=25 Steve Peters (Guest)
on 2006-03-08 16:01
(Received via mailing list)
On Wed, Mar 08, 2006 at 11:00:42PM +0900, Nick Snels wrote:
> 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.
>

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
5befe95e6648daec3dd5728cd36602d0?d=identicon&s=25 Robert Klemme (Guest)
on 2006-03-08 16:20
(Received via mailing list)
Nick Snels wrote:
> 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
E34b5cae57e0dd170114dba444e37852?d=identicon&s=25 Logan Capaldo (Guest)
on 2006-03-08 19:15
(Received via mailing list)
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.
91308e9bc88cb069fd1bcf88e910d042?d=identicon&s=25 Nick Snels (nicksnels)
on 2006-03-09 08:42
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

Robert Klemme wrote:
>
> try this:
>
> sql = `perl vendor\\sql\\sql.pl "#{@question.sql}"`
>
> Regards
>
>     robert
4ab06a38273fa1f5f14bbbca592ee031?d=identicon&s=25 Rob Pitt (Guest)
on 2006-03-09 10:29
(Received via mailing list)
Slightly OTT, I accidently ran a perl script with:

ruby script.pl

The other day, and it executed fine!!!!
4ab06a38273fa1f5f14bbbca592ee031?d=identicon&s=25 Rob Pitt (Guest)
on 2006-03-09 10:29
(Received via mailing list)
Look at them gem called "session". It's nice for executing processes.
E34b5cae57e0dd170114dba444e37852?d=identicon&s=25 Logan Capaldo (Guest)
on 2006-03-10 00:12
(Received via mailing list)
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!!!!

Was it

print "Hello, world!\n"

?
Dbd2eec32e5c673f74e9e35665bdf3e8?d=identicon&s=25 Hiep Nguyen (hiepnguyen)
on 2011-11-02 09:31
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/' );

How can we deal with this character.

your help is very appriciated

Hiep
Dbd2eec32e5c673f74e9e35665bdf3e8?d=identicon&s=25 Hiep Nguyen (hiepnguyen)
on 2011-11-02 09:44
I use
<<perl script.pl>> instead <<ruby script.pl>>

and it works
BTW Thanks you
This topic is locked and can not be replied to.