我需要使用 sendkeys 函数关闭命令提示符窗口,但是当我使用下面的代码时,它不起作用,因为正在运行某些 betch 文件,因此它不采用以下这些选项。
require 'win32ole'
system("start cmd.exe")
sleep(5)
# Create an instance of the Wscript Shell:
wsh = WIN32OLE.new('Wscript.Shell')
# Try to activate the command window:
if wsh.AppActivate('cmd.exe')
sleep(1)
wsh.SendKeys('cd \\')
wsh.SendKeys('{ENTER}')
# change the directory path where mtn folder is residing
wsh.SendKeys('cd ')
wsh.SendKeys "C://mtn-3//mtn-2.2//"
wsh.SendKeys('{ENTER}')
wsh.SendKeys('cd bin')
wsh.SendKeys('{ENTER}')
#run the cad test node file
wsh.SendKeys('CadTestNode.bat')
wsh.SendKeys('{ENTER}')
wsh1.SendKeys('Exit')
wsh1.SendKeys('{ENTER}')
我还尝试用以下内容替换最后两行以终止该过程。
wsh.SendKeys "^(c)"
wsh.SendKeys('{ENTER}')
但它仍然无法终止在命令提示符下运行的进程。
有没有其他方法可以终止在命令提示符窗口中运行的批处理过程?