"ruby script.rb" versus "xterm -e ruby script.rb"

Discussion in 'Ruby' started by Sy, Apr 16, 2005.

  1. Sy

    Sy Guest

    Ok, so I decided to hack around with a project I might feasably get to
    work. Strangely enough, it actually works. Except for reasons
    unknown, I'm forced to include a kludge so that it works
    _consistantly_. I'm curious to learn about this inconsistancy, and
    because I simply have no clue, I'd like to ask for some opinions.

    Overview: Accept input and then launch that process.

    # ------ begin script
    command_line = gets.chomp
    command_line = "nohup " + command_line.to_s + "&exit"
    system(command_line)

    # we can still continue to do other stuff.
    # ------ end script
    script home: http://sysy.homeip.net/mw/index.php/TRN_-_Launcher

    Except that thanks to my preferred method of calling it, it only
    inconsistantly works.

    * Method 1 (always works):

    ruby script.rb
    xterm

    This launches the script, and when I type in "xterm", xterm gets
    launched and then script.rb exits.

    * Method 2 (rarely works)

    xterm -e ruby script.rb
    xterm

    This launches an xterm window which launches the script, and when I
    type in "xterm", xterm only *sometimes* launches.


    * Note: freely replace "xterm" with "rxvt".. both seem to act the same


    * The Kludge

    Append this:

    pause = gets

    and the launcher always works as expected, with both methods of
    running the script.


    Or append this:

    10000.times do
    puts "do something stupid to delay exiting"
    end

    and (for me), the launcher always works as expected. However, when I
    lowered this to 1,000 it was still inconsistant.

    Yes, I didn't know how to make ruby pause / think in a more
    "efficiant" non-horribly-kludged way. But my intutition told me that
    xterm -e had xterm exit so fast that the script it was supposed to
    execute.. wasn't.

    --

    So.. I am guessing that during a failure in "xterm -e ruby script.rb"
    one of these must be true:

    * xterm is not launching ruby script.rb
    * ruby is not running script.rb
    * script.rb is not launching my command (via "system")
    * "nohup" within script.rb is not launching my command
    * my command is having problems with being executed in this manner.

    --

    Ideas?
    What have I missed?
    Sy, Apr 16, 2005
    #1
    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. Matthew Louden
    Replies:
    1
    Views:
    6,874
    Scott M.
    Oct 11, 2003
  2. Russ

    script versus code versus ?

    Russ, Jun 10, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,478
  3. Christoffer Sawicki
    Replies:
    5
    Views:
    239
    Christoffer Sawicki
    Sep 2, 2006
  4. Paul Butcher
    Replies:
    12
    Views:
    686
    Gary Wright
    Nov 28, 2007
  5. Mario Gr
    Replies:
    3
    Views:
    290
    Mario Gr
    Jul 4, 2009
Loading...

Share This Page