[#13775] Problems with racc rule definitions — Michael Neumann <neumann@...>

15 messages 2001/04/17
[#13795] Re: Problems with racc rule definitions — Minero Aoki <aamine@...> 2001/04/18

Hi,

[#13940] From Guido, with love... — Dave Thomas <Dave@...>

52 messages 2001/04/20

[#13953] regexp — James Ponder <james@...>

Hi, I'm new to ruby and am coming from a perl background - therefore I

19 messages 2001/04/21

[#14033] Distributed Ruby and heterogeneous networks — harryo@... (Harry Ohlsen)

I wrote my first small distributed application yesterday and it worked

15 messages 2001/04/22

[#14040] RCR: getClassFromString method — ptkwt@...1.aracnet.com (Phil Tomson)

It would be nice to have a function that returns a class type given a

20 messages 2001/04/22

[#14130] Re: Ruby mascot proposal — "Conrad Schneiker" <schneik@...>

Guy N. Hurst wrote:

21 messages 2001/04/24
[#14148] Re: Ruby mascot proposal — Stephen White <spwhite@...> 2001/04/24

On Tue, 24 Apr 2001, Conrad Schneiker wrote:

[#14188] Re: Ruby mascot proposal — matz@... (Yukihiro Matsumoto) 2001/04/25

Hi,

[#14193] Re: Ruby mascot proposal — "W. Kent Starr" <elderburn@...> 2001/04/25

On Tuesday 24 April 2001 23:02, Yukihiro Matsumoto wrote:

[#14138] Re: python on the smalltalk VM — Conrad Schneiker <schneik@...>

FYI: Thought this might be of interest to the JRuby and Ruby/GUI folks.

27 messages 2001/04/24
[#14153] Re: python on the smalltalk VM — Andrew Kuchling <akuchlin@...> 2001/04/24

Conrad Schneiker <schneik@austin.ibm.com> writes:

[#14154] array#flatten! question — Jim Freeze <jim@...> 2001/04/24

Hello.

[#14159] Can I insert into an array — Jim Freeze <jim@...> 2001/04/24

Ok, this may be a dumb question, but, is it possible to insert into an

[#14162] Re: Can I insert into an array — Dave Thomas <Dave@...> 2001/04/24

Jim Freeze <jim@freeze.org> writes:

[#14289] RCR: Array#insert — Shugo Maeda <shugo@...> 2001/04/27

At Wed, 25 Apr 2001 01:28:36 +0900,

[#14221] An or in an if. — Tim Pettman <tjp@...>

Hi there,

18 messages 2001/04/25

[#14267] Re: Ruby mascot proposal — "Conrad Schneiker" <schneik@...>

Danny van Bruggen,

16 messages 2001/04/26

[#14452] How to do it the Ruby-way 3 — Stefan Matthias Aust <sma@3plus4.de>

First a question: Why is

21 messages 2001/04/30

[ruby-talk:13630] Win32API: GenerateConsoleCtrlEvent not working under NT?

From: ptkwt@...1.aracnet.com (Phil Tomson)
Date: 2001-04-13 01:10:03 UTC
List: ruby-talk #13630
Here's one for the Win32 gurus out there.

I'm trying to make a timed system command under Windows that sends a 
CONTROL-C (^C) to the program that it spawns after a specified amount of 
time has passed.  Here's the code I have now:

######################start of code################3
 require 'Win32API'
 require 'timeout'
 CREATE_NEW_CONSOLE = 0x10
 CREATE_NEW_PROCESS_GROUP = 0x00000200
 DETACHED_PROCESS  = 0x08
 WAIT_TIMEOUT = 0x102
 CTRL_C_EVENT = 0
 CreateProcess = 
Win32API.new("kernel32","CreateProcess",['L','P','L','L','L','L','L','L','P','P'],'L')
 GetExitCodeProcess = 
Win32API.new("kernel32","GetExitCodeProcess",['L','P'],'L')
 WaitForSingleObject = 
Win32API.new("kernel32","WaitForSingleObject",['L','L'],'L')
 TerminateProcess = 
Win32API.new("kernel32","TerminateProcess",['L','L'],'L')
 CloseHandle = Win32API.new("kernel32","CloseHandle",['L'],'L')
 GenerateConsoleCtrlEvent = 
Win32API.new("kernel32","GenerateConsoleCtrlEvent",['L','L'],'L')
    

def timedSystemCommand( command, redirFile, time=100 )
    puts "command is: #{command}\n"
    fputc = Win32API.new("crtdll","fputc", ['L','L'],'L')
    killed = 0
    exitcode = "\0" * 32 
    si = [68].pack("L") + "\0" * 64
    pi = "\0" * 16;
    ######
    if redirFile
       tmpfile = File.new("tmp","w")
       save_stdout = $stdout.clone
       $stdout.reopen(tmpfile)
    end
    
CreateProcess.Call(0,"#{command}",0,0,1,CREATE_NEW_PROCESS_GROUP,0,0,si,pi)  
    hProcess = pi.unpack("LLLL")[0]
    hThread  = pi.unpack("LLLL")[1]
    dwProcessId = pi.unpack("LLLL")[2]
    dwThreadId = pi.unpack("LLLL")[3]
    a = WaitForSingleObject.Call( hProcess, time*1000 )
    if a==WAIT_TIMEOUT
      puts "got a timeout error"
      puts "send ^C!"
      GenerateConsoleCtrlEvent.Call(CTRL_C_EVENT, dwProcessId )
      killed = 1
    end
    GetExitCodeProcess.Call(hProcess, exitcode)
    exitcode = exitcode.unpack("L")
    CloseHandle.Call(hProcess)
    if redirFile
       $stdout.reopen(save_stdout)
    end
    save_stdout.close if save_stdout
    return killed, exitcode
 end

#########################end of code############################

On Windows 98 the above code works fine.  Under Windows NT and 2000, 
however, the program gets launched and the timeout condition happens, but 
the CTRL_C_EVENT that is supposed to be sent by GenerateConsoleCtrlEvent 
is never received (or sent, maybe?) so the application continues on it's 
merry way and is not killed.  

WinNT/2000 should be able to handle all of these functions OK - could it 
be a problem with Cygwin?.  I also tried a C version of the above (a C 
Ruby extension) and got the same results on NT (again I was using Cygwin 
to compile).  

Phil

In This Thread

Prev Next