'echo' without trailing newline

To echo a text without the writing of the ending newline (like echo -n under POSIX), type :

echo | set /p="<text>"

where <text> is the text to display.

This commands returns an errorlevel of 1, so you have to add || true to reset the errorlevel.

Setting a variable with the result of a command

To put the result of a command in an environment variable, type :

<command> > <file>
- set /p <variable>= < <file>

where :

  • <command> is the command from which you want to retrieve the result,
  • <variable> the name of the environment variable in which you want to store the result of the above command,
  • <file> : the name of a temporary file which can be deleted afterwards.

DOS command return value

The return value of a DOS command can be retrieved through %ERRORLEVEL%. A value other then 0 usually indicates an error.


Copying to clipboard : … | clip.

There is a way to copy from clipboard, but it involves PowerShell.

Also see Cygwin section.

Using a command output as input of another command


Example to open the http://q37.info/ web site when ouputed by a echo command:

FOR /F %G IN ('echo http://q37.info/') DO start %G

This work as command line. It seems you have to use %%G instead of %G (both times) in a batch file (no tested)