Mortifer Topic Starter
Posts: 4
Experience: Beginner OS: Unknown
|
 |
« on: February 01, 2012, 12:36:47 PM » |
|
Hi gents
I'm making a batch file to change a file extension "jogger" to "jogger.pack" Then run an third-party program "runner.exe" that using "jogger.pack" file. What I got so far:
ren Jogger Jogger.pack runner.exe Pause
While Runner.exe is being use, jogger.pack remain the same. After the Runner.exe closed, I need to change the "Jogger.pack" filename back to just "Jogger" again. The cycle repeat of adding extension, run program, and removing extension whenever the user running the bat file.
I don't know how to detect when "runner.exe" closes to do the remove naming.
If possible, perhaps to write code that remove the extension when user close the bat file command window, .
regard
|
|
|
|
|
|
|
Salmon Trout
Thanked: 546 Posts: 7,950
Computer: Specs Experience: Beginner OS: Unknown
|
 |
« Reply #2 on: February 01, 2012, 01:00:46 PM » |
|
I don't know how to detect when "runner.exe" closes to do the remove naming. :loop REM Wait 60,000 milliseconds (1 second) PING 1.1.1.1 -n 1 -w 60000 >NUL REM check tasklist to see if runner.exe is running REM if it is go to :loop tasklist | findstr /I "runner.exe" > nul && goto loop REM you get here after runner.exe stops REM do your rename stuff next
|
Proud to be European
|
|
|
Squashman
Thanked: 25 Posts: 342
Experience: Experienced OS: Other

|
 |
« Reply #3 on: February 01, 2012, 01:28:42 PM » |
|
I guess I am confused on this. Batch files are sequential processing. It will not go on to the next command until the previous one completes. At least I have never run into an instance of this not happening. Not sure why you couldn't use the START command with the wait switch either. So I guess I am not sure why we would need to use tasklist to see if it is still running.
|
|
|
|
|
|
|
Mortifer Topic Starter
Posts: 4
Experience: Beginner OS: Unknown
|
 |
« Reply #5 on: February 01, 2012, 02:43:21 PM » |
|
Hi gents I'm new at this so thank you very much for the speedy response  The code Salmon provided works superbly. I tried messing around with Squash Start /wait switch too. However, I later found out that it doesn't work on 32-bit GUI app which "runner.exe" unfortunately is. Thank you all again
|
|
|
|
« Last Edit: February 01, 2012, 02:56:54 PM by Mortifer »
|
IP logged
|
|
|
|
Squashman
Thanked: 25 Posts: 342
Experience: Experienced OS: Other

|
 |
« Reply #6 on: February 01, 2012, 03:31:54 PM » |
|
Well I am pretty sure Notepad is a 32bit gui application and I have posted examples on this very forum executing notepad with and without notepad and the batch file paused each time until I closed notepad.
|
|
|
|
|
Squashman
Thanked: 25 Posts: 342
Experience: Experienced OS: Other

|
 |
« Reply #7 on: February 01, 2012, 06:20:10 PM » |
|
Well this certainly is interesting. It is kind of a mixed bag of what applications will wait and which ones will not. Seems like all the Microsoft apps I throw at it will wait. Chrome will not. Firefox waits. itunes waits Skype waits
|
|
|
|
|
Squashman
Thanked: 25 Posts: 342
Experience: Experienced OS: Other

|
 |
« Reply #8 on: February 01, 2012, 09:35:42 PM » |
|
Found a few more things. http://www.ericphelps.com/scripting/samples/index.htm#RunYou can use the Wait For Title or Wait for Exe VBscripts to pause your script. Although I guess it really doesn't hurt to do keep polling for the process with Tasklist. Especially if you want to keep it pure batch.
|
|
|
|
|
Mortifer Topic Starter
Posts: 4
Experience: Beginner OS: Unknown
|
 |
« Reply #9 on: February 02, 2012, 07:07:28 PM » |
|
I tried it on Runner.exe and it won't wait  . The wait switch would have been lovely as users might run the program for a large amount of time and i'm not sure what 700+ checks might do to performance. Ye, VBscript will likely give me a brain aneurysm. Perhaps if i'm 20 years younger I might try to learn it 
|
|
|
|
|
Squashman
Thanked: 25 Posts: 342
Experience: Experienced OS: Other

|
 |
« Reply #10 on: February 02, 2012, 07:56:19 PM » |
|
The Vbscript is a no brainer to use. All you do is download it and use. Nothing to edit inside the code at all.
You would use it just like this.
ren Jogger Jogger.pack runner.exe WaitForexe.vbs runner.exe ren Jogger.pack Jogger
|
|
|
|
|
|
|
Squashman
Thanked: 25 Posts: 342
Experience: Experienced OS: Other

|
 |
« Reply #12 on: February 02, 2012, 09:38:25 PM » |
|
OK. But where is WaitForexe.vbs
Found a few more things. http://www.ericphelps.com/scripting/samples/index.htm#Run You can use the Wait For Title or Wait for Exe VBscripts to pause your script. Although I guess it really doesn't hurt to do keep polling for the process with Tasklist. Especially if you want to keep it pure batch.
|
|
|
|
|
|
|
Squashman
Thanked: 25 Posts: 342
Experience: Experienced OS: Other

|
 |
« Reply #14 on: February 03, 2012, 05:21:31 AM » |
|
From the link bySquashman
On Error Resume Next If WScript.Arguments.Count <> 1 Then WScript.Echo "Waits for an application to shut down. Usage:" & vbCrLf & Ucase(WScript.ScriptName) & " ""Program.exe""" & vbCrLf & "Where ""Program.exe"" is the executable name of the application you are waiting for." Else blnRunning = True Do While blnRunning = True Set objWMIService = GetObject("winmgmts:\\.\root\cimv2") Set colItems = objWMIService.ExecQuery("Select Name from Win32_Process where Name='" & Wscript.Arguments(0) & "'",,48) blnRunning = False For Each objItem in colItems blnRunning = True Next WScript.Sleep 500 Loop End IfNo quite so simple. The thing giving by Salmon Trout is more simple.
And this is coming from a guy who sits there and recommends PowerShell to people who ask questions about batch files and never provides them a PowerShell script. Then you see myself, Raven or Salmon come along and write the Batch file that can do it. I am sure the batch script code from Salmon Trout was not so simple for the O/P to understand either. I basically said the VBscript was easy to use! I showed the BATCH code on how to use the VBscript. How hard can that really be! You don't have to know VBscript to use the code at all. Just download it and use it in your batch file. 
|
|
|
|
|