problem executing bash script from ruby

Discussion in 'Ruby' started by Tom Cloyd, Jul 16, 2009.

  1. Tom Cloyd

    Tom Cloyd Guest

    I have little experience with this sort of thing, but it looked fairly
    straightforward. I'm in trouble, however.

    Details:

    From /home/tomc/Ruby-work/setnet/bin/ I launch "./setnet". This dir
    contains:
    mkrdoc.sh setnet

    "./setnet" contains these lines (among others), and works fine:

    manager = SN::DBManager.new()
    manager.startup

    The "SN.rb" module is in "/home/tomc/Ruby-work/setnet/lib/setnet", and
    contains a method with this code snippet -

    puts "\n=== generating new rdocs for SetNet ==="
    system("ls") # to verify where I am in the filesystem
    system("./mkrdoc.sh")
    if $? != 0
    puts "*** command failed: status = #{$?.exitstatus}"
    end

    This snippet executes by means of selection from a menu, with this result -

    === generating new rdocs for SetNet ===
    mkrdoc.sh setnet
    *** command failed: status = 127

    mkrdoc.sh contains:

    cd ../lib/setnet
    echo "dir--"
    ls
    echo "rdoc executing --"
    rdoc -N -x ./doc

    What I'm trying to do is acquire the functionality of generating new
    rdocs for my program without having to manually go back to a command
    line. Every attempt I made to make a single "system()" call from within
    ruby, to generate the rdocs, have failed. In my experience, rdoc is
    excessively quirky. I've spent most of today trying to get it to do some
    simple things, and failing, even though I've very carefully following
    the documentation. I do have something that works - that "rdoc -N -s
    /doc" command, but only when it's executed from within the right dir.

    Since -
    * I'm allowed one command per "system()" call, and
    * upon return from that call, the present working dir is reset to its
    prior state...

    my only option appears to be to issue the commands I'd use in a manual
    interaction with the CLI from within a script file, and that's what I'm
    trying to do.

    My questions:

    1. Is there some obvious reason by my attempt to execute mkrdoc.sh is
    failing?
    2. How can I make use of the process status output I've captured? I've
    searched Pickax 3rd ed., and with Google, and I'm not receiving much
    enlightenment. What do the "big boys/girls" do with this status output?

    Thanks very much for any help anyone can offer.

    Tom

    --

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Tom Cloyd, MS MA, LMHC - Private practice Psychotherapist
    Bellingham, Washington, U.S.A: (360) 920-1226
    << >> (email)
    << TomCloyd.com >> (website)
    << sleightmind.wordpress.com >> (mental health weblog)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     
    Tom Cloyd, Jul 16, 2009
    #1
    1. Advertising

  2. [Note: parts of this message were removed to make it a legal post.]

    An option would be to run the bash script inside a PTY... but that makes it
    simply to complex for something that could all be done from within ruby...Have
    you try calling rdoc straight from ruby instead of bash?

    2009/7/15 Tom Cloyd <>

    > I have little experience with this sort of thing, but it looked fairly
    > straightforward. I'm in trouble, however.
    >
    > Details:
    >
    > From /home/tomc/Ruby-work/setnet/bin/ I launch "./setnet". This dir
    > contains:
    > mkrdoc.sh setnet
    >
    > "./setnet" contains these lines (among others), and works fine:
    >
    > manager = SN::DBManager.new()
    > manager.startup
    >
    > The "SN.rb" module is in "/home/tomc/Ruby-work/setnet/lib/setnet", and
    > contains a method with this code snippet -
    >
    > puts "\n=== generating new rdocs for SetNet ==="
    > system("ls") # to verify where I am in the filesystem
    > system("./mkrdoc.sh")
    > if $? != 0
    > puts "*** command failed: status = #{$?.exitstatus}"
    > end
    >
    > This snippet executes by means of selection from a menu, with this result -
    >
    > === generating new rdocs for SetNet ===
    > mkrdoc.sh setnet *** command failed: status = 127
    > mkrdoc.sh contains:
    >
    > cd ../lib/setnet
    > echo "dir--"
    > ls
    > echo "rdoc executing --"
    > rdoc -N -x ./doc
    >
    > What I'm trying to do is acquire the functionality of generating new rdocs
    > for my program without having to manually go back to a command line. Every
    > attempt I made to make a single "system()" call from within ruby, to
    > generate the rdocs, have failed. In my experience, rdoc is excessively
    > quirky. I've spent most of today trying to get it to do some simple things,
    > and failing, even though I've very carefully following the documentation. I
    > do have something that works - that "rdoc -N -s ./doc" command, but only
    > when it's executed from within the right dir.
    >
    > Since -
    > * I'm allowed one command per "system()" call, and
    > * upon return from that call, the present working dir is reset to its prior
    > state...
    >
    > my only option appears to be to issue the commands I'd use in a manual
    > interaction with the CLI from within a script file, and that's what I'm
    > trying to do.
    >
    > My questions:
    >
    > 1. Is there some obvious reason by my attempt to execute mkrdoc.sh is
    > failing?
    > 2. How can I make use of the process status output I've captured? I've
    > searched Pickax 3rd ed., and with Google, and I'm not receiving much
    > enlightenment. What do the "big boys/girls" do with this status output?
    >
    > Thanks very much for any help anyone can offer.
    >
    > Tom
    >
    > --
    >
    > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    > Tom Cloyd, MS MA, LMHC - Private practice Psychotherapist
    > Bellingham, Washington, U.S.A: (360) 920-1226
    > << >> (email)
    > << TomCloyd.com >> (website) << sleightmind.wordpress.com >> (mental
    > health weblog)
    > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    >
    >
    >
     
    Louis-Philippe, Jul 16, 2009
    #2
    1. Advertising

  3. Tom Cloyd

    Luke Cowell Guest

    1) I googled: exist status 127 - here's the response:
    If a command is not found, the child process created to execute it
    returns a status of 127.

    I think you should try specifying the absolute path of the shell script.

    2) If you want to capture the output of your command, you should use the
    %x{} notation or the `` notation.

    c = %x{pwd}
    is equivalent to:
    c = `pwd`

    the system command differs from these in that it output the results to
    stdout and any assignments just contain true or false depending on the
    exit status. That would be useful if you wanted to run a script and
    cared only about whether the script was successful or not.

    a = system("pwd")
    puts a
    0

    check out:
    http://www.ruby-doc.org/core/classes/Kernel.html#M005971

    Here's another example summarizing what I've described here. You'd
    probably do well to open irb and type the commands out individually.

    lukebook:~ lukec$ irb
    irb(main):001:0> a = `pwd`
    => "/Users/lukec\n"
    irb(main):002:0> puts a
    /Users/lukec
    => nil
    irb(main):003:0> a.upcase
    => "/USERS/LUKEC\n"


    Luke
    --
    Posted via http://www.ruby-forum.com/.
     
    Luke Cowell, Jul 16, 2009
    #3
    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. William Park

    (patch for Bash) GTK+2 + Bash

    William Park, Jul 11, 2005, in forum: XML
    Replies:
    3
    Views:
    2,331
    William Park
    Jul 14, 2005
  2. Gros Bedo
    Replies:
    2
    Views:
    1,370
    Piet van Oostrum
    Jul 10, 2008
  3. Gros Bedo
    Replies:
    1
    Views:
    692
    Piet van Oostrum
    Jul 10, 2008
  4. Tom Cloyd
    Replies:
    2
    Views:
    119
    Bil Kleb
    Jul 16, 2009
  5. Fred

    executing bash comands with pipe

    Fred, Jun 26, 2007, in forum: Perl Misc
    Replies:
    4
    Views:
    162
    J├╝rgen Exner
    Jun 26, 2007
Loading...

Share This Page