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.
Nick S. (Guest)
on 2006-03-08 16: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
Steve P. (Guest)
on 2006-03-08 17:01
(Received via mailing list)
On Wed, Mar 08, 2006 at 11:00:42PM +0900, Nick S. 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 P.
removed_email_address@domain.invalid
Robert K. (Guest)
on 2006-03-08 17:20
(Received via mailing list)
Nick S. 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
Logan C. (Guest)
on 2006-03-08 20:15
(Received via mailing list)
On Mar 8, 2006, at 10:01 AM, Steve P. 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.
Nick S. (Guest)
on 2006-03-09 09: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 K. wrote:
>
> try this:
>
> sql = `perl vendor\\sql\\sql.pl "#{@question.sql}"`
>
> Regards
>
>     robert
Rob Pitt (Guest)
on 2006-03-09 11:29
(Received via mailing list)
Slightly OTT, I accidently ran a perl script with:

ruby script.pl

The other day, and it executed fine!!!!
Rob Pitt (Guest)
on 2006-03-09 11:29
(Received via mailing list)
Look at them gem called "session". It's nice for executing processes.
Logan C. (Guest)
on 2006-03-10 01: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"

?
Hiep N. (Guest)
on 2011-11-02 10: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
Hiep N. (Guest)
on 2011-11-02 10: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.