[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Call Perl script from Ruby

Nick Snels

3/8/2006 2:01:00 PM

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

--
Posted via http://www.ruby-....


7 Answers

Steve Peters

3/8/2006 3:01:00 PM

0

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.
>

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

Robert Klemme

3/8/2006 3:18:00 PM

0

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

robert

Logan Capaldo

3/8/2006 6:13:00 PM

0


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.

Nick Snels

3/9/2006 7:43:00 AM

0

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


--
Posted via http://www.ruby-....


Rob Pitt

3/9/2006 9:28:00 AM

0

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.
>



Rob Pitt

3/9/2006 9:28:00 AM

0

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.
>



Logan Capaldo

3/9/2006 11:11:00 PM

0


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"

?