Getting START /WAIT to work when app already running

Anyone know how to get /WAIT on the START command to work when Mp3tag is already running?

My batch file uses

 START "" /WAIT "%~dp0tools\Mp3tag\Mp3tag.exe" /fp:"temp\"

to run Mp3tag and wait for completion before for processing commands, but it fails to wait if Mp3Tag is already running.


I think this is only possible if you have several start commands in the same batch file.
If you try to open several instances of MP3tag then it is not possible as theses instances start independently from each other and then discover that there is already an instance running.

Thanks. I'm not trying to open several instances. I'm trying to open a single instance in this batch file. The failure occurs if there is already in instance open when the batch file starts.

If you start the batch file and there is already an open MP3tag then you do open several instances.
The batch file only knows abouts its very local environment so that one command in the chain can listen to the response of the previous command.
Everything that runs outside this environment is not under control of the batch process.
So as it is not possible to start several instances of MP3tag any attempt to start another instance will fail.

I don't see several instances. I see the batch file command take control of the existing instance.


If it completely failed, I'd be happy! Instead it takes control of the existing instance and the /WAIT fails.

Mp3tag is a windows application but not a command line application.
Once Mp3tag has been started from the command line, the windows process get its own environment and has no further binding to the command process.
Furthermore Mp3tag checks itself if it has been started again.
Mp3tag only takes the new process's parameters, kills the new process, and updates itself with the new parameters.


That's not what I see. When START /WAIT works, it works.

That's certainly consistent with the problem I am having.

If anyone knows a solution, please do say. E.g. a command utility proven to reliably terminate Mp3tag.

Yes, my bad, you are right.

For example ...
START "" /WAIT notepad.exe
... will wait until notepad has been closed.

That's the same when starting Mp3tag.exe.

Huh, what was the problem, please?
Ah yes I see, the new still invisible Mp3tag process will be killed immediately.
And the command script takes the next step.

You can look for a running Mp3tag process ... and if exist, then kill it.

pslist.exe "Mp3tag" -e 1>NUL 2>NUL

IF %ERRORLEVEL%==0 (ECHO.Mp3tag is running.) ELSE (ECHO.Mp3tag is not running.)
IF %ERRORLEVEL%==0 (pskill.exe "Mp3tag" 1>NUL 2>NUL)

You can find pslist.exe and pskill.exe from the Sysinternals suite there ...


Yup, that's it.

Thanks. That works. Which is a surprise, since nowhere do I see that pslist is supposed to set %errorlevel%.

Kill loses any unsaved work in the app, so I decided to pause instead:

pslist.exe "Mp3tag" -e 1>NUL 2>NUL
REM If Mp3tag already running, manually close before proceeding.
If %ERRORLEVEL%==0 (pause)

Thanks again. This is a big improvement, because it also prevents that command Mp3tag.exe running a different and incompatible version of the app (I have both V2.44 and later) which was occasionally causing false metadata.

I'm glad to help you.
Hmm ... you may rename Mp3tag.exe version 2.44 to another name like "Mp3tag244.exe" and run it under that name, so you can see it in the processlist with that name and decide what to do.
Renaming seems not to change the behaviour of Mp3tag killing the second invocation.


Yes, that would be even safer - thanks.

I would like a patch to the .exe for this. I see no good reason for Mp3tag preventing me running it twice from separate portable installs.

I just tried it and what you had originally works for me in Windows7 Pro. My batch file consists of the following:

start /wait mp3tag.exe /fp:"D:\Music\! Test\Flac\Alison Krauss\Two Highways"
start /wait mp3tag.exe /fp:"D:\Music\! Test\Flac\Freddie Hubbard\Rollin'"

The behavior that I see is that Mp3tag opens with the Alison Krauss album. When Mp3tag is closed, it then opens again with the Freddie Hubbard album. I assume that's what you want.

Thanks but it is not. I asked "Anyone know how to get /WAIT on the START command to work when Mp3tag is already running?" and if you try your example when Mp3tag is already running you'll see your /WAIT fails.

Ah, yes. I didn't understand that part. It would never have occurred to me that closing Mp3tag first would be too much trouble.

Again, see /t/15071/1 .

This fails on Win7:

R:\>pslist.exe /accepteula "Mp3tag" -e  1>NUL 2>NUL
R:\>REM if Mp3tag already running, manually close before proceeding.
R:\>If 9009 == 0 (pause)

Any ideas?

EDIT: My mistake. A PATH error meant the .exe was not found. But "2>NUL" hid the error message! Dangerous. So I have removed it.

D, here's a solution using only internal commands, and no risky 2>nul:

REM Ensure Mp3tag is closed - loop while running
tasklist /fi "imagename eq Mp3tag.exe" | find "Mp3tag.exe" 1>nul
If %ERRORLEVEL%==0 (cls & echo Close Mp3tag! & goto checkmp3tag)