[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Starting and stopping a child process in Windows

Jon A. Lambert

4/27/2005 5:04:00 AM

Alexey Verkhovsky wrote:
> What is the best / most reliable / most obvious way to start and kill
> a child process under Windows? This child process happens to be a Webrick
> application, and I don't
> care about being platform-dependent in this case.

You might use CreateProcess from Win32api.
The PID is returned in the last parameter, the process_information
structure.
Then use that PID in calling OpenProcess to get the Handle to use
when calling TerminateProcess.

--
J Lambert





1 Answer

Jon A. Lambert

4/27/2005 5:53:00 AM

0

Jon A. Lambert wrote:
> You might use CreateProcess from Win32api.
> The PID is returned in the last parameter, the process_information
> structure.
> Then use that PID in calling OpenProcess to get the Handle to use
> when calling TerminateProcess.

Here's a bit of code that partly works. That is it does get the process id.
You'd have to look up all the actual values in the windows headers
for the options you want.


require 'Win32API'

createProcess =
Win32API.new("kernel32.dll","CreateProcess",'pplllllppp','L')
startupinfo = [ 68 ].pack("lx64")
procinfo = [ 0,0,0,0 ].pack("llll")
createProcess.call(nil,"write.exe", 0, 0, 1, 0, 0, "c:\\apps", startupinfo,
procinfo)

processid = procinfo.unpack("llll")[2]

puts processid

# works up to here
openProcess = Win32API.new("kernel32.dll","OpenProcess",'lll','L')
handle = openProcess.call(0, 0, processid)

puts handle

terminateProcess = Win32API.new("kernel32.dll","TerminateProcess",'ll','L')
terminateProcess.call(handle, 0)