How to join output of two commands in one line?

1.9k Views Asked by At

For example, following commands (in Windows 7):

date/t>>t.txt
time/t>>t.txt

create following lines in t.txt:

Fri 06/12/2015 
01:37 PM

Is it possible to join output of two commands (see above) in one line (see below)?

Fri 06/12/2015 01:37 PM

The above mentioned goal can be reached by command:

echo %date% %time%

But it is not an answer on this question, because this question is not about only above commands.

3

There are 3 best solutions below

6
On BEST ANSWER

For any number of commands, in a simpler way:

@echo off
setlocal EnableDelayedExpansion

set "output="
for %%a in ("date /t" "time /t" "echo Hello world") do (
   for /F "delims=" %%b in ('%%~a') do set "output=!output! %%b"
)
echo %output:~1%>> t.txt
1
On

The output of two commands can be joined in one line by using following commands (in batch file):

for /f "delims=" %%x in ('date/t') do set d=%%x
for /f "delims=" %%x in ('time/t') do set t=%%x
echo %d%%t%>>t.txt
1
On

The output of two commands can be joined in one line also by using following commands (in batch file):

date /t>t_t.txt
set /p t=<t_t.txt
time /t>t_d.txt
set /p d=<t_d.txt
echo %t%%d%>>t.txt