McMahon, Chris wrote:
Hello...
I'm new to Ruby and I need some help with managing an external
process. I'm on Windows, and I want to do something (overly simplified)
like this:File.new(file_to_be_handled_by_outside_process.txt)
system ("C:\\filewatcher.exe file_to_be_handled_by_outside_process.txt")
<write stuff to file_to_be_handled_by_outside_process.txt>The foreign process started by system() never stops. I need to
return control to the Ruby script after the system() call so that I can
have the Ruby script generate information for the foreign process to
handle. Any suggestions would be welcome... -Chris
Just doing the system call in a thread works on windows,
Thread.new do
system "foo"
end
# code to keep processing while foo runs...
For example:
Thread.new do
system "sleep 10"
puts "slept"
end
loop do
puts "hello"
sleep 1
end
I ran this on linux, but I'm pretty sure it works on windows too.
But you may want to consider popen, as was suggested, so you don't have concurrency problems with the two processes accessing the file.