The closest I can come up with is:
echo 123 > out.txt
However this gives a trailing space and also a trailing newline.
http://gnuwin32.sourceforge.net/packages.html
coreutils contains "echo". You can use the "-n" flag to supress the trailing newline
I've used this with success:
echo|set /p="123" > test.txt
>text.txt (echo|set /p="123")
Oct 11, 2012 at 21:04
set /p=123
). It's fine with the double quotes in place (set /p="123"
).
Oct 11, 2012 at 21:25
In PowerShell:
write-output 123 | out-file test.txt
There is no trailing space, but there is a newline.
If you want to do this in cmd, the answer you provided in your question is the "correct" way, but there are obvious formatting issues
I think you want this for text-based output:
type filename > output.txt
Use copy con
C:\tmp>copy con mynewfile
This is my new file
I am typing stuff
^Z
1 file(s) copied.
C:\tmp>type mynewfile
This is my new file
I am typing stuff
Press Control-Z to end input
'con' is a keyword signifying console.
copy src dest
copy con mynewfile
src - con - console
dest - mynewfile - destination
cat 123 > out.txt
; I've just edited it to refer toecho
.