sendkeys 関数を使用してコマンド プロンプト ウィンドウを閉じる必要があります。
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}')
また、プロセスを終了するために、最後の 2 行を以下に置き換えてみました。
wsh.SendKeys "^(c)"
wsh.SendKeys('{ENTER}')
それでもコマンドプロンプトで実行中のプロセスを終了することはできません。
コマンドプロンプトウィンドウで実行中のバッチプロセスを終了する他の方法はありますか?