Re: How can I play a Wav file from batch/cmd script?
Milesahead - thanks for the tip. Your method does absolutely work, but
the problem is that it leaves us with a media player hanging around in
memory, even if minimized. It also retains the active window, even if
the batch file continues other operations.
Surprisingly to me, there's relatively little forum chatter on this
specific topic under Vista, but after rooting around I did come up with
a method that works fine. Requires 3 lines in a batch file:
start /min "mediaplayer" "mediafile"
timeout /T "N"
taskkill /IM "mediaplayer"
Your method for playing the file is shorter & more elegant, but this
allows selecting the media player for type of file (for instance, one
player for flac files, another for mp3s).
The timeout command is necessary, because otherwise the following
command, taskkill, will kill the mediaplayer task before it has a chance
to play the sound file. Switch /T N refers t the seconds you want to
command processor to wait before loading the next line of the batch file
(no quotes for seconds number) Also means you have to have a rough idea
of how many seconds the soundfile takes, but that's not a big deal.
The taskkill command zaps the program from memory. For this operation
you don't need a fully qualified path name, since it is looks fo the
image name (vlc.exe, for example) that is in the task list. Finally, if
you want to avoid extraneous info sent to the screen, redirect lines 2
and 3 to nul.
Thanks again for taking an interest.