gron gron
gron gron

Reputation: 69

output redirection in windows on the same line

is it possible to redirect the output of two different commands in a windows batch file on the same line? For example the output of the first command to go on line 1 of my file and when i'll execute command 2 to append itself on the same line as the previous output. Thank you

Upvotes: 1

Views: 3446

Answers (2)

Jiri
Jiri

Reputation: 16625

You can redirect output to file or append output to file:

echo LINE1, > file.txt
echo LINE2 >> file.txt

But there will always be a newline even if the command does not output CRLF (it is the case with echo command, you cannot suppress it)

To have output on the same line you need to use this approach:

set content=

ECHO LINE1 > temp.txt
for /f "delims=" %%i in (temp.txt) do set content=%%i

ECHO LINE2 > temp.txt
for /f "delims=" %%i in (temp.txt) do set content=%content% %%i

ECHO %content%> result.txt
del temp.txt

Upvotes: 2

Attila
Attila

Reputation: 28772

Unless the first program outputs a newline character, you can do the shell redirection-concatenation:

prog1 > out.txt
prog2 >> out.txt

Upvotes: 0

Related Questions