X
x1
I'm trying to create a method that will kick off a new process, return
it's pid.. while allowing the return code to also be captured for
later examination..
[on windows platform]
class Exec
def process_handler
# if I do the following below, it will yield the
# pid which is great, but because I did not
# write pipe it to {}, I don't think it's possible to capture
the return_level
return IO.popen("ruby -e 'sleep 2' &exit 33").pid
end
end
puts Exec.new.process_handler.to_s # =3D> 3389
puts $? >> 8 # =3D> gives me an error because I didnt start IO.popen with {=
}
As a work around, I tried the following:
class Exec
def process_handler
# if I do the following below, it will yield the
# pid which is great, but because I did not
# write pipe it to {}, I don't think it's possible to capture
the return_level
Thread.new {
p =3D IO.popen("ruby -e 'sleep 2' &exit 33") {}
$p_return_code =3D $? >> 8
}
return p, $p_return_code
end
end
The problem here is, p will not be defined until the process has
finished writing to the pipe {}, which will prevent the return of the
pid..
Any suggestions on this? I'm not able to test this code as I'm using
a machine @ an internet cafe.
Kind regards,
Chris
it's pid.. while allowing the return code to also be captured for
later examination..
[on windows platform]
class Exec
def process_handler
# if I do the following below, it will yield the
# pid which is great, but because I did not
# write pipe it to {}, I don't think it's possible to capture
the return_level
return IO.popen("ruby -e 'sleep 2' &exit 33").pid
end
end
puts Exec.new.process_handler.to_s # =3D> 3389
puts $? >> 8 # =3D> gives me an error because I didnt start IO.popen with {=
}
As a work around, I tried the following:
class Exec
def process_handler
# if I do the following below, it will yield the
# pid which is great, but because I did not
# write pipe it to {}, I don't think it's possible to capture
the return_level
Thread.new {
p =3D IO.popen("ruby -e 'sleep 2' &exit 33") {}
$p_return_code =3D $? >> 8
}
return p, $p_return_code
end
end
The problem here is, p will not be defined until the process has
finished writing to the pipe {}, which will prevent the return of the
pid..
Any suggestions on this? I'm not able to test this code as I'm using
a machine @ an internet cafe.
Kind regards,
Chris