here is the thing, i need to move a previous ruby program from Linux to
Windows, but Win doesn’t support fork, how can i refine the code to make
it work on Win?
i googled a lot but still didn’t get it, can anyone help me here?i paste
the code below:
def exec_cmd(cmd, toen=false, tmout=3600)
return false if !$AveSubPID.nil?
ret = fork
if ret.nil? then
exec “#{cmd}”
end
$AveSubPID = ret
succ=true
if (toen) then
begin
timeout(tmout) {
Process.wait(ret)
$AveSubPID = nil
succ=$?.success?
$AveErrno = $?.exitstatus
}
rescue Timeout::Error => e
echo "(timeout) "
kill_sub_process(ret)
$AveSubPID = nil
succ = false
$AveErrno = $?.exitstatus
end
else
Process.wait(ret)
$AveSubPID = nil
succ=$?.success?
$AveErrno = $?.exitstatus
end
return succ
end
here is the thing, i need to move a previous ruby program from Linux to
Windows, but Win doesn’t support fork, how can i refine the code to make
it work on Win?
i googled a lot but still didn’t get it, can anyone help me here?
Have you considered using Cygwin (http://cygwin.com) and the ruby
package it provides? That will give you an emulated fork. While Cygwin
is not a panacea for porting Unix applications to Windows, it may work
for you.
Have you considered using Cygwin (http://cygwin.com) and the ruby
package it provides? That will give you an emulated fork. While Cygwin
is not a panacea for porting Unix applications to Windows, it may work
for you.
-Jeremy
Hi, Jeremy, i knew cywin works for it, but cygwin has a memory limit for
our usage, that’s why we won’t use cygwin any more.
what i need now it to move it into Mingw and get it work…
thanks for your quick reply, i appreciate it:)
It might help to forward this on to the RubyInstaller group, since Luis
Lavena is maintaining the Ruby installer for Windows, he might know how
to
handle it (or how to get DevKit to work with it):
Thread.new { system “dd”, “if=/dev/zero”, “of=/dev/null” }
=> #<Thread:0x7f81cb7337b0 sleep>
A better way IMO is to use the #spawn method which calls the external
process and doesn’t wait for it to complete. It immediately returns the
PID of the spawned process. Since Ruby 1.9 this works even on Windows.
i tried using win32-process to emulate #fork, although the code need no
changes, the behavior of win32-process’ fork is different from Linux
fork, finally i used #spawn, and it seems work well
A better way IMO is to use the #spawn method which calls the external
process and doesn’t wait for it to complete. It immediately returns the
PID of the spawned process. Since Ruby 1.9 this works even on Windows.
Vale,
Marvin
Hi, Marvin
is #spawn’s behavior just similar to fork+exec?
i am not very clear how to change the code to use #spawn instead, could
you please give me some sample code to show how to using #spawn instead
of fork+exec? thanks!
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.