exec (new process or new thread?) to continue

Discussion in 'Ruby' started by aidy, Feb 24, 2009.

  1. aidy

    aidy Guest

    Hi,

    I have fired off an exe with the kernal method exec

    loader_app = "#{Dir.getwd}/PublishUi.exe"
    exec(loader_app)

    The exec method seems to hold up the process

    so

    exec(loader_app)
    puts "we got here"

    Will not print "we got here" till I close the app.

    I am not sure whether I should use a new thread or a new process here,
    or whether there is an alternative.

    Thanks

    Aidy
     
    aidy, Feb 24, 2009
    #1
    1. Advertising

  2. aidy

    List.rb Guest

    On Feb 24, 2009, at 8:19 AM, aidy <> wrote:

    > Hi,
    >
    > I have fired off an exe with the kernal method exec
    >
    > loader_app = "#{Dir.getwd}/PublishUi.exe"
    > exec(loader_app)
    >
    > The exec method seems to hold up the process
    >
    > so
    >
    > exec(loader_app)
    > puts "we got here"
    >
    > Will not print "we got here" till I close the app.
    >
    > I am not sure whether I should use a new thread or a new process here,
    > or whether there is an alternative.
    >
    > Thanks
    >
    > Aidy
    >
    >


    IO.popen(an_exe)
     
    List.rb, Feb 24, 2009
    #2
    1. Advertising

  3. aidy

    lasitha Guest

    On Tue, Feb 24, 2009 at 6:59 PM, List.rb <> wrote:
    > On Feb 24, 2009, at 8:19 AM, aidy <> wrote:
    >
    >> The exec method seems to hold up the process
    >> so
    >>
    >> exec(loader_app)
    >> puts "we got here"
    >>
    >> Will not print "we got here" till I close the app.

    >
    > IO.popen(an_exe)
    >


    And with ruby 1.9, Kernel.spawn:
    http://ruby-doc.org/core-1.9/classes/Kernel.html#M006071

    Cheers,
    lasitha.
     
    lasitha, Feb 24, 2009
    #3
  4. aidy wrote:
    > Hi,
    >
    > I have fired off an exe with the kernal method exec
    >
    > loader_app = "#{Dir.getwd}/PublishUi.exe"
    > exec(loader_app)
    >
    > The exec method seems to hold up the process
    >
    > so
    >
    > exec(loader_app)
    > puts "we got here"
    >
    > Will not print "we got here" till I close the app.
    >
    > I am not sure whether I should use a new thread or a new process here,
    > or whether there is an alternative.
    >
    > Thanks
    >
    > Aid



    exec doesn't hold up the process, it replaces it completely[1]. Your
    second example will never print "we got here".

    Assuming you do not need to communicate with, wait on, or know anything
    about the process you are starting, you can use fork[2] and exec this way:

    fork { exec load_app }

    -Justin


    [1] http://ruby-doc.org/core/classes/Kernel.html#M005979
    [2] http://ruby-doc.org/core/classes/Kernel.html#M005980
     
    Justin Collins, Feb 24, 2009
    #4
  5. aidy wrote:
    > Hi,
    >
    > I have fired off an exe with the kernal method exec
    >
    > loader_app = "#{Dir.getwd}/PublishUi.exe"
    > exec(loader_app)


    Since you appear to be on windows, you can't fork, but you can do this:

    Thread.new do
    loader_app = "#{Dir.getwd}/PublishUi.exe"
    system(loader_app)
    end

    # continue with other stuff here

    This is a fairly cross-platform way to handle it. Of course on windows,
    you can also do

    system "start ..."

    and then you don't even need a ruby thread.

    --
    vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
     
    Joel VanderWerf, Feb 24, 2009
    #5
  6. I like this pattern:

    def fire_and_forget(&block)
    pid = fork do
    begin
    yield
    ensure
    Process.exit!
    end
    end
    Process.detach pid
    end

    A little bit safer then just using 'fork'...

    Taken from a post here:
    http://www.caboo.se/articles/2006/10/14/premcache-caching-an
    d-precaching-with-memcached

    Justin Collins wrote:
    > Assuming you do not need to communicate with, wait on, or know anything
    > about the process you are starting, you can use fork[2] and exec this
    > way:
    >
    > fork { exec load_app }
    >
    > -Justin
    >
    >
    > [1] http://ruby-doc.org/core/classes/Kernel.html#M005979
    > [2] http://ruby-doc.org/core/classes/Kernel.html#M005980


    --
    Posted via http://www.ruby-forum.com/.
     
    Colin Brumelle, Apr 8, 2009
    #6
    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. rabbits77
    Replies:
    1
    Views:
    509
    John C. Bollinger
    Feb 25, 2004
  2. Hal Vaughan
    Replies:
    11
    Views:
    1,120
    Gordon Beaton
    May 22, 2006
  3. tedsuzman
    Replies:
    2
    Views:
    7,092
    Michel Claveau, résurectionné d'outre-bombe inform
    Jul 21, 2004
  4. raj

    webservice return value but continue some process

    raj, Jul 24, 2003, in forum: ASP .Net Web Services
    Replies:
    3
    Views:
    146
    Steven Licciardi
    Jul 24, 2003
  5. Cod
    Replies:
    6
    Views:
    138
Loading...

Share This Page