Reputation: 23
i have a simple problem that i can't manage to solve...
i use this line of batch to print the result of a command in a file without the carriage return :
echo | set /P=%tmp% > %~n1.txt
but it keeps adding an extra space at the end that i don't want...
i've read some other posts but it is my first batch program so i'm a little lost with there solutions :p
i've tried :
%^^^cmd | set /P=%tmp% > %~n1.txt
Any ideas ?
Thanks !
Upvotes: 2
Views: 472
Reputation: 130819
You simply need some quotes.
echo | set /P "=%tmp%" > %~n1.txt
Although there is a more efficient way to do it without the pipe. Note that quotes still should be used.
set /p "=%tmp%" >"%~n1.txt" <nul
If you don't include the quotes, then you would need the following:
set /p =%tmp%>%~n1.txt <nul
But the unquoted form would fail if the value of %tmp%
was a digit, or if it ends with space followed by a digit. It would fail because the digit would be treated as a file handle to be used by the redirection. For example, 1 equates to stdout.
The quotes are the simplest manner to cleanly avoid the file handle issue.
Upvotes: 2