Windows Vista Forums

How can I play a Wav file from batch/cmd script?
  1. #1



    Newbie
    Join Date : Sep 2008
    Posts : 4
    VistaHP32
    Local Time: 06:28 PM

    How can I play a Wav file from batch/cmd script?

    Apologize if this has been covered elsewhere, but I haven't been able to find it.

    I'm using Vista32HP. In Win98 & NT I've been able to play wav files from command scripts, but in Vista nothing I've tried seems to work. Can anyone tell me how to do it? Thanks,


      My System SpecsSystem Spec

  2. #2



    Newbie
    Join Date : Sep 2008
    Posts : 2
    Vista Home Premium x64
    Local Time: 02:28 AM


     

    Re: How can I play a Wav file from batch/cmd script?

    Do you mean, play files from "command line" (cmd) ???
    If you do, yep, it can be done...
    Type in command prompt (or compose a batch file to do it...)

    <audio_program> /play /close <file>

    Ex. to launch WMP to play a wav file
    %ProgramFiles%\Windows Media Player\wmplayer.exe /play /close C:\music\1.wav
    ---------------------
    hope it's work for you

      My System SpecsSystem Spec

  3. #3



    Newbie
    Join Date : Sep 2008
    Posts : 4
    VistaHP32
    Local Time: 06:28 PM


      Thread Starter

    Re: How can I play a Wav file from batch/cmd script?

    Thanks for the reply, but that syntax doesn't work for me with any media player so far.

    I really need this functionality to run from a batch/cmd file for audible cues for certain events. I don't want to see the player interface, and I want it to exit after playing the wave file. I've been trying to get this kind of command to work:
    start /min "player.exe" /play /close "wavefile.wav"

    With some media players I can get them to start minimized and play the file, but then they try to parse the /play /close switches as media files and stop with error messages. They also move the active window to the media player. With WMP, it starts but doesn't play the file, much less exit gracefully.

    I know there has to be a simple way to get this done. I just can't figure out how. Any advice would be much appreciated.

      My System SpecsSystem Spec

  4. #4
    MilesAhead's Avatar

    Eclectician



    Join Date : Jan 2008
    Posts : 1,986
    Vista Home Premium 64 bit SP1
    Local Time: 07:28 PM
    usa

     

    Re: How can I play a Wav file from batch/cmd script?

    Just for grins try
    start /min file.wav

    Start should open the wav file with whatever is associated with .wav files.

      My System SpecsSystem Spec

  5. #5



    Newbie
    Join Date : Sep 2008
    Posts : 4
    VistaHP32
    Local Time: 06:28 PM


      Thread Starter

    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.

      My System SpecsSystem Spec

  6. #6
    MilesAhead's Avatar

    Eclectician



    Join Date : Jan 2008
    Posts : 1,986
    Vista Home Premium 64 bit SP1
    Local Time: 07:28 PM
    usa

     

    Re: How can I play a Wav file from batch/cmd script?

    Million ways to skin the cat. You might want to investigate
    AutoIt3 scripting language. It's free and gives you a lot
    more control. It's great for launching other apps and
    even sending keystrokes once they are open.

    As an example, I made a general purpose AutoIt3 app
    to launch another application or open a file with
    the associated app, move it to x y pos on screen
    and optionally resize the window in about 20 lines
    of code.

    Batch scripting is okay but AutoIt makes it easier
    to do error checking and reporting and has a syntax
    that's easy for anyone who has used batch or
    bash, or Rexx, or Basic. Plus you can right click
    on the script and compile it to .exe so that having
    the interpreter on the target machine is not an issue.

      My System SpecsSystem Spec

  7. #7



    Newbie
    Join Date : Sep 2008
    Posts : 4
    VistaHP32
    Local Time: 06:28 PM


      Thread Starter

    Re: How can I play a Wav file from batch/cmd script?

    Sounds really useful. Will definitely check it out.

      My System SpecsSystem Spec

How can I play a Wav file from batch/cmd script? problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
RE: runas script to launch batch file Anteaus VB Script 0 15 Dec 2009
Help with a Batch file script (FTP) MariusK Vista General 2 31 Jul 2008
Re: How to play sounds from a batch file Synapse Syndrome Vista General 0 15 Dec 2007
How to run PS script with parameters from a batch file =?Utf-8?B?Um9tYW4gS3V6bWlu?= PowerShell 1 09 Sep 2006
How to run PS script with parameters from cmd batch file? =?Utf-8?B?Um9tYW4gS3V6bWlu?= PowerShell 5 22 Jul 2006