exec (new process or new thread?) to continue

A

aidy

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
 
L

List.rb

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)
 
J

Justin Collins

aidy said:
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
 
J

Joel VanderWerf

aidy said:
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.
 
C

Colin Brumelle

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 said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top