Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #2052 > unrolled thread
| Started by | Ethan Huo <firewall888@hotmail.com> |
|---|---|
| First post | 2011-03-31 09:18 -0500 |
| Last post | 2011-04-02 08:50 -0500 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.lang.ruby
how to refine the code to avoid using fork on windows? Ethan Huo <firewall888@hotmail.com> - 2011-03-31 09:18 -0500
Re: how to refine the code to avoid using fork on windows? Tony Arcieri <tony.arcieri@medioh.com> - 2011-03-31 22:13 -0500
Re: how to refine the code to avoid using fork on windows? Ethan Huo <firewall888@hotmail.com> - 2011-04-02 08:50 -0500
| From | Ethan Huo <firewall888@hotmail.com> |
|---|---|
| Date | 2011-03-31 09:18 -0500 |
| Subject | how to refine the code to avoid using fork on windows? |
| Message-ID | <21a67789ae6ce6e83dd836329b50863f@ruby-forum.com> |
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
--
Posted via http://www.ruby-forum.com/.
[toc] | [next] | [standalone]
| From | Tony Arcieri <tony.arcieri@medioh.com> |
|---|---|
| Date | 2011-03-31 22:13 -0500 |
| Message-ID | <AANLkTikY3mq4D97aAycL2d3mkNSmBF_mEkAz6Z5thg3E@mail.gmail.com> |
| In reply to | #2052 |
[Note: parts of this message were removed to make it a legal post.]
Check out the childprocess gem: https://github.com/jarib/childprocess
On Thu, Mar 31, 2011 at 8:18 AM, Ethan Huo <firewall888@hotmail.com> wrote:
> 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
>
> --
> Posted via http://www.ruby-forum.com/.
>
>
--
Tony Arcieri
Medioh! Kudelski
[toc] | [prev] | [next] | [standalone]
| From | Ethan Huo <firewall888@hotmail.com> |
|---|---|
| Date | 2011-04-02 08:50 -0500 |
| Message-ID | <30d0f1b4c2d37875222b69a5663a2be5@ruby-forum.com> |
| In reply to | #2052 |
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 -- Posted via http://www.ruby-forum.com/.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.ruby
csiph-web