windows - Ultimate Kill for Ruby Script -


i have unstoppable ruby script need able stop. here following code:

require 'win32ole'  wsh = win32ole.new("wscript.shell")  def filetoarray(file)     x = []     file.foreach("#{file}") |line|         x << line.to_s.split('')     end     return x.flatten! end tests = filetoarray("c:\\xampp\\htdocs\\x\\script\\includes\\classes.php")  sleep 10 x = 0 y = tests.length while x <= y     send = tests[x]     speed = 0.025     if x == y         print "test complete"         break()     #you guys don't need see code, it's detecting keys      #in array , reading them file. important know incrementing based on sent keys     else         x += 1     end end 

my problem classes.php reading 4,000 lines long , takes long time through. if messes up, have wait until finished. there no way me stop loop running until finished unless log out everything, ctrl+alt+del option: logout. i've tried curses i've tried gets on exit. ctrl^c doesn't work either. i'd rather have written in solution, otherwise wouldn't mind knowing few keys killswitch process a.k.a. "kill it, kill keys"

you read each byte in array, how long array if let in run till end ? filling array of hundreds of thousands takes long time indeed. should see rest of code decide if there no better way, , why win32ole object ?

if standard windows keys interrupt jog don't word (ctrl-c or ctrl-break) , can't use taskmanager, surely console still responsive.

here script do. put in endless loop have terminate it. process.pid shows process id. in advance open console , when want terminate script enter following

taskkill /f /pid 5532 

the /f forcing terminate, number pid script

# encoding:utf-8 stdout.sync = true s1 = file.read __file__ puts process.pid class string     def to_a       while true # endless loop testing kill         each_byte.inject([]){|result, char| result << char}       end     end end  p s1.to_a 

tested windows 7 , ruby mri 1.9.3

edit: based on comment here way send keys program if understand correctly want don't need split string in advance.

require 'win32ole' #for script autoit3 must installed  s1 = "a string of thousands of characters"  # activate correct window appclass ai.opt("wintitlematchmode", 4) appclass = "[class:xxxxxxxx]"    # retrieved autoit window info  ai = win32ole.new("autoitx3.control") ai.winactivate(appclass)  # or handle handle = "[handle:#{ai.wingethandle(appclass)}]"  ai.winactivate(handle)  # send keys, controlkeys or words program ai.send('{home}') #you can send control keys  s1.each_byte{|char| ai.send(char); sleep 1} #to send char after char  s1[0..10].each_byte{|char| ai.send(char); sleep 1} #to send first 10 chars 

Comments