gerwim Posted October 18, 2010 Share Posted October 18, 2010 Hi there, So I'm starting a .bat file which is a CMD process. I give this process a PID variable and trying to close it doesn't work. This is my code: Func Start() Global $PID = Run("server_nogui.bat", "") GUICtrlSetState($BTN_Restart, $GUI_ENABLE) GUICtrlSetState($BTN_Stop, $GUI_ENABLE) GUICtrlSetState($BTN_Start, $GUI_DISABLE) GUICtrlSetData($status, "Running") EndFunc Func Stop() MsgBox(0,"Debug","PID: "& $PID) ProcessClose($PID) GUICtrlSetState($BTN_Restart, $GUI_DISABLE) GUICtrlSetState($BTN_Stop, $GUI_DISABLE) GUICtrlSetState($BTN_Start, $GUI_ENABLE) GUICtrlSetData($status, "Stopped") EndFunc The process keeps running, but when I do for example ProcessClose("excel.exe") it works.. Google didn't help me either. Thanks in advance! Link to comment Share on other sites More sharing options...
iamtheky Posted October 18, 2010 Share Posted October 18, 2010 That works fine (see below). The problem lies elsewhere. Maybe the contents of the batch? Global $PID If fileexists(@ScriptDir & "\test.bat") Then FileDelete(@ScriptDir & "\test.bat") sleep (1000) Endif _Make () _Start () _Stop() Func _Make() filewrite (@ScriptDir & "\test.bat" , "echo test" & @CRLF & "pause") sleep (1000) EndFunc Func _Start() Global $PID = Run("test.bat", "") sleep (2000) EndFunc Func _Stop() MsgBox(0,"Debug","PID: "& $PID) ProcessClose($PID) If Not ProcessExists ($PID) Then MsgBox(0,"Closed","PID: "& $PID & " has been closed") Endif EndFunc ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
gerwim Posted October 18, 2010 Author Share Posted October 18, 2010 Hmm this is very strange. Could it be that it's not having a pause or something? Since I do have the PID, it just doesn't close it. Link to comment Share on other sites More sharing options...
gerwim Posted October 18, 2010 Author Share Posted October 18, 2010 This code does work: WinKill("C:\WINDOWS\system32\cmd.exe") This is fine for me too, BUT if someone has a different windows folder or different windows drive, it doesn't work.. Any other way? Link to comment Share on other sites More sharing options...
willichan Posted October 18, 2010 Share Posted October 18, 2010 This code does work: WinKill("C:\WINDOWS\system32\cmd.exe") This is fine for me too, BUT if someone has a different windows folder or different windows drive, it doesn't work.. Any other way? @WindowsDir My UDFs: Barcode Libraries, Automate creation of any type of project folder, File Locking with Cooperative Semaphores, Inline binary files, Continue script after reboot, WinWaitMulti, Name Aggregator, Enigma, CornedBeef Hash Link to comment Share on other sites More sharing options...
iamtheky Posted October 18, 2010 Share Posted October 18, 2010 WinTitleMatchMode, 2 should just let you call it ('cmd') or call it with "cmd /c" from within the batch so that it terminates itself ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
gerwim Posted October 18, 2010 Author Share Posted October 18, 2010 @WindowsDirHehe, why I didn't thought of that. /facepalm. Thanks =)WinTitleMatchMode, 2 should just let you call it ('cmd')or call it with "cmd /c" from within the batch so that it terminates itselfAwesome, I used the match mode, works like a charm =) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now