Call Perl script from Ruby

Discussion in 'Ruby' started by Nick Snels, Mar 8, 2006.

  1. Nick Snels

    Nick Snels Guest

    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-forum.com/.
     
    Nick Snels, Mar 8, 2006
    #1
    1. Advertising

  2. Nick Snels

    Steve Peters Guest

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

    On Wed, Mar 08, 2006 at 11:00:42PM +0900, Nick Snels wrote:
    > 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


    --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--
     
    Steve Peters, Mar 8, 2006
    #2
    1. Advertising

  3. 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
     
    Robert Klemme, Mar 8, 2006
    #3
  4. --Apple-Mail-28-325625152
    Content-Transfer-Encoding: 7bit
    Content-Type: text/plain;
    charset=US-ASCII;
    delsp=yes;
    format=flowed


    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.


    --Apple-Mail-28-325625152--
     
    Logan Capaldo, Mar 8, 2006
    #4
  5. Nick Snels

    Nick Snels Guest

    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-forum.com/.
     
    Nick Snels, Mar 9, 2006
    #5
  6. Nick Snels

    Rob Pitt Guest

    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, Mar 9, 2006
    #6
  7. Nick Snels

    Rob Pitt Guest

    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.
    >
     
    Rob Pitt, Mar 9, 2006
    #7
  8. --Apple-Mail-33-429905240
    Content-Transfer-Encoding: 7bit
    Content-Type: text/plain;
    charset=US-ASCII;
    format=flowed


    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"

    ?


    --Apple-Mail-33-429905240--
     
    Logan Capaldo, Mar 9, 2006
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Wet Basement
    Replies:
    1
    Views:
    2,555
    BobMonk
    Jul 15, 2003
  2. dpackwood
    Replies:
    3
    Views:
    1,839
  3. pj
    Replies:
    3
    Views:
    310
  4. Petterson Mikael

    Execute another perl script from my perl script

    Petterson Mikael, Jan 5, 2005, in forum: Perl Misc
    Replies:
    3
    Views:
    150
    Paul Lalli
    Jan 5, 2005
  5. Replies:
    20
    Views:
    808
    Gunnar Hjalmarsson
    Jan 18, 2005
Loading...

Share This Page