Running batch script in MFC
-
Hi, I have a tricky issue here: A MFC dialog based App calls a Batch script. This batch script again calls a SSH tool to login to a remote PC. This is to enable FTP service on WinNT remote PC. This is done multiple times in my MFC app. SSH login take approximately 30 seconds and somehow I can not make the control waut there until the SSL login goes thru. I have used the following code to run the Sample BAT file:
-TestFTP.bat- ssh.exe -pw @ net start ftp exit
In MFC I use WaitForSingleObject to wait for completion of TestFTP.bat:SHELLEXECUTEINFO ShExecInfo = {0}; ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS; ShExecInfo.hwnd = NULL; ShExecInfo.lpVerb = NULL; ShExecInfo.lpFile = "TestFTP.bat"; ShExecInfo.lpParameters = ""; ShExecInfo.lpDirectory = NULL; ShExecInfo.nShow = SW_HIDE; ShExecInfo.hInstApp = NULL; ShellExecuteEx(&ShExecInfo); WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
However, WaitForSingleObject returns immediately and Not sure whats wrong here. How to wait till the batch completes? Any help would be great! Thanks Vikas -
Hi, I have a tricky issue here: A MFC dialog based App calls a Batch script. This batch script again calls a SSH tool to login to a remote PC. This is to enable FTP service on WinNT remote PC. This is done multiple times in my MFC app. SSH login take approximately 30 seconds and somehow I can not make the control waut there until the SSL login goes thru. I have used the following code to run the Sample BAT file:
-TestFTP.bat- ssh.exe -pw @ net start ftp exit
In MFC I use WaitForSingleObject to wait for completion of TestFTP.bat:SHELLEXECUTEINFO ShExecInfo = {0}; ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS; ShExecInfo.hwnd = NULL; ShExecInfo.lpVerb = NULL; ShExecInfo.lpFile = "TestFTP.bat"; ShExecInfo.lpParameters = ""; ShExecInfo.lpDirectory = NULL; ShExecInfo.nShow = SW_HIDE; ShExecInfo.hInstApp = NULL; ShellExecuteEx(&ShExecInfo); WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
However, WaitForSingleObject returns immediately and Not sure whats wrong here. How to wait till the batch completes? Any help would be great! Thanks VikasDo you know
WaitForSingleObject
[^] function returns a value? Are you aware that you should check that value? :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
Hi, I have a tricky issue here: A MFC dialog based App calls a Batch script. This batch script again calls a SSH tool to login to a remote PC. This is to enable FTP service on WinNT remote PC. This is done multiple times in my MFC app. SSH login take approximately 30 seconds and somehow I can not make the control waut there until the SSL login goes thru. I have used the following code to run the Sample BAT file:
-TestFTP.bat- ssh.exe -pw @ net start ftp exit
In MFC I use WaitForSingleObject to wait for completion of TestFTP.bat:SHELLEXECUTEINFO ShExecInfo = {0}; ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS; ShExecInfo.hwnd = NULL; ShExecInfo.lpVerb = NULL; ShExecInfo.lpFile = "TestFTP.bat"; ShExecInfo.lpParameters = ""; ShExecInfo.lpDirectory = NULL; ShExecInfo.nShow = SW_HIDE; ShExecInfo.hInstApp = NULL; ShellExecuteEx(&ShExecInfo); WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
However, WaitForSingleObject returns immediately and Not sure whats wrong here. How to wait till the batch completes? Any help would be great! Thanks VikasMay be it seems to you, while debugging it might completes. Try this,
-TestFTP.bat-
ssh.exe -pw @
net start ftp
pause // batch file execution waits here until user press any key.and check whether WaitForSingleObject returns immediately. And also, check your batch file executes correctly, ShExecInfo.nShow = SW_SHOW; // you can change it later. ssh.exe -pw @ // if ssh is not installed it returns error. similarly.
-
Hi, I have a tricky issue here: A MFC dialog based App calls a Batch script. This batch script again calls a SSH tool to login to a remote PC. This is to enable FTP service on WinNT remote PC. This is done multiple times in my MFC app. SSH login take approximately 30 seconds and somehow I can not make the control waut there until the SSL login goes thru. I have used the following code to run the Sample BAT file:
-TestFTP.bat- ssh.exe -pw @ net start ftp exit
In MFC I use WaitForSingleObject to wait for completion of TestFTP.bat:SHELLEXECUTEINFO ShExecInfo = {0}; ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS; ShExecInfo.hwnd = NULL; ShExecInfo.lpVerb = NULL; ShExecInfo.lpFile = "TestFTP.bat"; ShExecInfo.lpParameters = ""; ShExecInfo.lpDirectory = NULL; ShExecInfo.nShow = SW_HIDE; ShExecInfo.hInstApp = NULL; ShellExecuteEx(&ShExecInfo); WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
However, WaitForSingleObject returns immediately and Not sure whats wrong here. How to wait till the batch completes? Any help would be great! Thanks VikasAt one point in time, batch files were processed one line at a time, with an open and close each time. So technically, the batch file did complete, but there was no distinction between the first line completing vs. the whole thing being complete. One other thing to try is
CreateProcess()
instead ofShellExecuteEx()
."Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne