[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

exec (new process or new thread?) to continue

aidy

2/24/2009 1:15:00 PM

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
5 Answers

list. rb

2/24/2009 1:29:00 PM

0





On Feb 24, 2009, at 8:19 AM, aidy <aidy.lewis@googlemail.com> 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)



lasitha

2/24/2009 1:58:00 PM

0

On Tue, Feb 24, 2009 at 6:59 PM, List.rb <list.rb@gmail.com> wrote:
> On Feb 24, 2009, at 8:19 AM, aidy <aidy.lewis@googlemail.com> 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.ht...

Cheers,
lasitha.

Justin Collins

2/24/2009 1:59:00 PM

0

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.ht...
[2] http://ruby-doc.org/core/classes/Kernel.ht...

Joel VanderWerf

2/24/2009 8:05:00 PM

0

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

Colin Brumelle

4/8/2009 8:35:00 PM

0

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-...
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.ht...
> [2] http://ruby-doc.org/core/classes/Kernel.ht...

--
Posted via http://www.ruby-....