Drivejunky95 Posted November 22, 2015 Share Posted November 22, 2015 Hi all I am new (today) to machine script. This is something I put together and will be trying tomorrow. cd /d "C:\path"Start Filename.batcd /d "H:\path"Start Program.exe :CHECKping -n 10 localhost 1> NULTASKLIST /v /fi "IMAGENAME eq program.exe" 2>&1 > NULIF ERRORLEVEL 1 GOTO CHECK taskkill /f /im cmd.exe /t If all goes well, filename.bat will run. Then a program will run. CMD will then check for program.exe until not found (exited), then close CMD. In this case program.exe does not work with start /wait I am wondering if the check will slow down my machine if run for a few hours. I am using Windows 7 x64, SSD, 16GB RAM and AMD 8350. Considering inserting a small timeout, but seems silly. Is there a way to slow down the check, but still close immediately if program.exe is closed? Link to comment Share on other sites More sharing options...
jaclaz Posted November 22, 2015 Share Posted November 22, 2015 Side notes. Always use a name or just a pair of double quotes when using the START command. http://ss64.com/nt/start.html You cannot really use TASKLIST like that, as it doesn't set an ERRORLEVEL, see: http://stackoverflow.com/questions/4969595/exit-status-of-tasklist-in-batch-file http://stackoverflow.com/questions/162291/how-to-check-if-a-process-is-running-via-a-batch-script I am not sure to understand the original idea, can you provide some details on what you actually *need* or *want* to do? jaclaz Link to comment Share on other sites More sharing options...
Drivejunky95 Posted November 22, 2015 Author Share Posted November 22, 2015 (edited) No problem:) Filename.bat is a looping xcopy /d with 5min timeout Program.exe is an application that makes frequent saves I need something that will start the .bat and the program, then close the .bat when the program is closed. Edited November 22, 2015 by Drivejunky95 Link to comment Share on other sites More sharing options...
jaclaz Posted November 22, 2015 Share Posted November 22, 2015 I still have no understanding of the final GOAL. I was expecting a description of the expected result or scope and - unless of course it is a trade secret of some kind - the contents of the batch and what is the actual "program.exe" would be another piece of useful info (as I am completely failing to imagine an executable that would not work with "START /W" ). You need to be aware of the risk of (possibly) slipping on a chocolate covered banana or more generally fall in the XYZ problem:http://homepage.ntlworld.com/jonathan.deboynepollard/FGA/put-down-the-chocolate-covered-banana.html jaclaz Link to comment Share on other sites More sharing options...
Drivejunky95 Posted November 22, 2015 Author Share Posted November 22, 2015 (edited) Ok, When I start program.exe I also want a looping batch file to start (see Filename.bat). This will save new files from program.exe to another directory. What isn't happening is when I close program.exe, the looping batch file is not closing, hence the **taskkill /f /im cmd.exe /t** I think I have narrowed it down some. Filename.bat@echo off:loopxcopy /y "C:\path" "H:\path" /dtimeout /t 20goto loop So using: Example.bat@echo offcd /d "H:\path"program.execd /d "C:\path"call Filename.bat :CHECKtimeout /t 10> nulTaskList /nh /fi "IMAGENAME eq program.exe" | find "program.exe" 2>&1 > nulIF ERRORLEVEL 1 GOTO CHECK taskkill /f /im cmd.exe /t Works, but prevents the CHECK due to no return of control from the looping Filename.bat Edited November 22, 2015 by Drivejunky95 Link to comment Share on other sites More sharing options...
jaclaz Posted November 22, 2015 Share Posted November 22, 2015 But why the two batches? I mean (IF I have understood the issue) wouldn't this single batch do nicely? @echo offcd /d "H:\path"program.execd /d "C:\path":loopxcopy /y "C:\path" "H:\path" /dtimeout /t 20:CHECKTaskList /nh /fi "IMAGENAME eq program.exe" | find "program.exe" 2>&1 > nulIF %ERRORLEVEL% NEQ 0 GOTO :looptaskkill /f /im cmd.exe /tThe ERRORLEVEL syntax has been modified, though the one you used is fine, because of this (it's only a habit, not really-really needed in most cases):http://www.robvanderwoude.com/errorlevel.php jaclaz Link to comment Share on other sites More sharing options...
Drivejunky95 Posted November 22, 2015 Author Share Posted November 22, 2015 Almost works, Example.bat@echo off cd /d H:\pathStart /b program.exe cd /d C:\pathcall Filename.bat And inside Filename.bat@echo off:looptimeout /t 10 > NULxcopy /y "C:\path" "H:\path" /dTaskList /nh /fi "IMAGENAME eq program.exe" | find "program.exe" 2>&1 > nulIF ERRORLEVEL 1 goto loop exit This is working, but the looping error level section is exiting while program.exe is still open Link to comment Share on other sites More sharing options...
Drivejunky95 Posted November 22, 2015 Author Share Posted November 22, 2015 Oh god, that looks complicated xD Will try it. Haha Link to comment Share on other sites More sharing options...
Drivejunky95 Posted November 22, 2015 Author Share Posted November 22, 2015 Awesome man! You killed it! Set the NEQ error level to 1 and "IF ERRORLEVEL NEQ" fixed it! Just for giggles I tried it in the original script and it worked! So that means using the ERRORLEVEL syntax like this in Windows 7 returns negative values! Link to comment Share on other sites More sharing options...
jaclaz Posted November 23, 2015 Share Posted November 23, 2015 Awesome man! You killed it! Set the NEQ error level to 1 and "IF ERRORLEVEL NEQ" fixed it! Just for giggles I tried it in the original script and it worked! So that means using the ERRORLEVEL syntax like this in Windows 7 returns negative values! Good , I guess that which ERRORLEVEL is set should be verified in the two cases (when the FIND actually finds the program.exe and when it doesn't) but the main thing is that it works . jaclaz 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