Windows command line tips

From Hydrogenaudio Knowledgebase
Revision as of 11:35, 24 February 2022 by Porcuswiki (talk | contribs) (Created page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Several useful applications and utilities are called from the command line; some GUIs are merely front-ends that call the commands for you. Double-clicking a CLI ("command line interface") application like flac.exe it will open a terminal window, scroll through some text, and then close without converting anything; this is much like the Windows "rename" command does nothing if it isn't told what to rename into what; flac.exe is intended to be given as a command with the file to be converted as an argument.

While CLI usage has been ubiquitous in *n*x (and MS-DOS), it may be alien to many users. This page gives some basic tips on how to utilize commands from Microsoft's cmd.exe; using PowerShell will be slightly different.

This page was written with command-line encoders/decoders in mind, such as flac.exe, wavpack.exe or CUETools with its command-line applications. Note that both flac.exe and wavpack.exe/wvunpack.exe support drag+drop: you can drag a .wav file onto flac.exe or wavpack.exe and it will be converted using default settings. The following is for the next step up.

Using a CLI

You can open a the cmd command prompt by Win-r cmd (that is: holding down the Windows logo key and hitting r, then in the popup mini-window typing cmd and hitting Enter). That will open a text window. Alternatively you can use Windows Explorer to navigate to a directory, Shift+rightclick an empty area of the directory window, and you will get an option to open a command-line window "here" - although with some setups, it will offer you PowerShell instead.

As an example, Monkey's Audio comes as an installer, but has a command-line encoder/decoder. If you have 64-bit Monkey's Audio installed under the default C:\Program Files\Monkey's Audio x64\ , you can navigate there. You will see a "MAC.exe" which is Monkey's audio's command-line application. Open a command-line there and give the command "mac.exe" or simply just "mac" (Windows is case-insensitive, unlike unices). It will return to you text that starts with e.g. the following:

--- Monkey's Audio Console Front End (v 7.33) (c) Matthew T. Ashland ---
Proper Usage: [EXE] [Input File] [Output File] [Mode]

Modes: 
  • The actual command that will do compression is e.g. mac inputfile.wav thenameyouwantfortheoutputfile.ape -c3000  ; where, the inputfile.wav either has to be in the same directory (it and it is unlikely to be in C:\Program Files\*) or you have to give the full path like "E:\wav files to be compressed\inputfile.wav" (with the quotation marks because of the whitespaces in there!).
  • Alternatively, you can navigate to E:\wav files to be compressed\inputfile.wav and try to run the mac.exe from there; then you need to give the command "C:\Program Files\Monkey's Audio x64\mac.exe" inputfile.wav thenameyouwantfortheoutputfile.ape -c3000 .
  • To avoid typing all the letters, see the next:

Not having to type the full path

Typing the full path - correctly - is a slow exercise, and can be avoided in a few ways. The easiest to accomplish is likely the System32 folder (see below), but users would likely familiarize themselves with the following anyway.

  • cmd supports tab completion: type C:\Pro and hit the <Tab> key and see what happens. Hitting <Tab> multiple times will likely cycle between "C:\Program Files" and "C:\Program Files (x86)" . From the former, hit \M so it says "C:\Program Files\M" and another <Tab>, and it will start cycling between subfolders starting with M. When it shows "C:\Program Files\Monkey's Audio x64" hit \ma and press <Tab>.
  • You can drag and drop files into the command line window. If you have a command-line window open, drag MAC.exe into it and drop. The window will type "C:\Program Files\Monkey's Audio x64\MAC.exe" for you. Hit space and drag and drop inputfile.wav. Now you have to enter the output file name with full path and the appropriate option at the end.
  • You can temporarily copy the .exe to where you are working. .\MAC will look in the directory you are.

You can also let Windows know where the exe resides, see the headline about the PATH variable.

Suggested portable setup without touching the PATH variable

Create a folder for all portable-use .exe's. Copy them there.

  • Suggestion: C:\bin ; a "bin" directory is typically used in *n*x systems for "binaries" (nothing to do with the recycle bin!). Advantages over e.g. "c:\programs_portable" are that it is easy to both type and tab-complete; you don't have to cycle through folders on "P" like "PerfLogs", "Program Files" etc.: C:\b<tab> (or \b<tab> if the window is open in a directory under C:)
  • You can put your portable applications into subfolders of \bin, and then either rely on tab completions (like \b<tab>\w<tab> to get to WavPack) or copy the relevant exe from the subfolder to \bin (say, copy wavpack.exe and wvunpack.exe from C:\bin\wavpack-5.4.0-x64 to C:\bin\ ). The latter has the downside that you will have to re-do the copying every time you fetch an update (e.g. from wavpack 4.80 to 5.4) with overwrite.


Alternative setups - use with caution!

The following approaches are not without risk to the novice user. The first one is easier than the second.

The C:\Windows\System32\ folder

Copy the executables into the folder, and Windows will know it (then you can use "wavpack" from anywhere like you use "dir"). Exercise caution if prompted to overwrite - what if something you want to copy has the same name as a standard Windows utility?

The PATH variable

PATH is a system variable that makes Windows aware of executables (you might see phrases like "requires the exe to be in PATH"). PATH is a list of directories (not files) where Windows will look for executables; it will not traverse subdirectories.

To a novice user, using a command-line to update PATH is risky business; one wrong character and it will replace rather than append - and furthermore, there is a length limit. This stackoverflow post gives how, as well as the warning. You might therefore want to add only a few directories - for example the "C:\bin" if you go that route.

If you want to update the PATH, it is safer in Windows 10 than in Windows 7 and below:

  • Hit the windows key and type environment. You will get options to edit the system environment variables (that will apply to all users) or the environment variables for your account only. (If you choose the latter you will not have to click an "Environment Variables" button low-right in the next window.)
  • Click the PATH. Hit Edit, and then New.
  • On the new line, type "C:\bin" and then commit the changes.

For audio encoders/decoders, an alternative to c:\bin will be to install the foobar2000 free encoder pack and add the folder C:\Program Files (x86)\foobar2000\encoders . You will then have access to those encoders from anywhere.