Subprocess under Win32

M

Michael Mueller

Hello!

Today I had some trouble with the app I'm working on. (Ruby 1.8.0
under Windows 2000).
Basically I want to read in some data from the serial port and do some
fancy stuff with that data....
Using the serialport-api I succeeded in reading in the data. However I
have the problem, that the following call blocks the whole process
until some data is read - unfortunately Ruby Threads won't help me in
this situation...
---
require "serialport/serialport.so"
@sp = SerialPort.new(port, 19200, 8, 1, SerialPort::NONE)
...
...
while(@continue) do
zeile = @sp.gets #This blocks!!!
#do someting
end

---
My app has a GUI and I want it to be responsive while waiting for the
data I tried various approaches for fixing that problem. Since there
is no fork() under Windows I used the "win32_popen"-library for
spawning a new process:

@serial_client_pid = IO.win32_popen3("serialreader.rb")[0].pid

My idea was to put the serial-port-reading-related-stuff in this
second ruby program in which I start a DRb-Server and and to fetch the
data via DRb from the parent app.
This sounds crazy and is imho really clumsy but it works!

The last problem that I didn't get to solve is, that when I quit the
app the second process won't get killed.
I tried it with
IO.win32_kill(@serial_client_pid)

Unfortunately the PID I get from the win32_open3-method is NOT the PID
of the second ruby-process but the PID of a "cmd"-Process (looked it
up in the taskmgr). Killing this process won't kill the ruby-process.

Do you guys have an idea how to solve this problem?
Or is there even a much morge elegant solution without DRb??? (Maybe
that part was just a mad idea...)

Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top