Page 1 of 1

Sending command to a single in a text file

Posted: 22 May 2021 13:44
by Ryobi
Hello,

Does anybody know to to single multiple commands with results to a single line to text file in windows 10 cmd.
What I want to do is send the name of the hostname of the computer and the date
The command are Hostname & date /t >> test.file.

This command only send the date, but the Hostname. I have tried Hostname & date /t without sending the output to a file and I notice that it displays
Hostname
Date

What I want is Hostname Date in a single line then send it to the textfile as a single line not two lines.
Is this possible?

Thanks

Re: Sending command to a single in a text file

Posted: 23 May 2021 00:43
by OJBakker
Yes, it is possible.

Code: Select all

@for /f %A in ('hostname') do @for /f "delims=" %B in ('date/t') do @echo %A %B > testfile.txt

Re: Sending command to a single in a text file

Posted: 23 May 2021 22:07
by Squashman
Why not....?

Code: Select all

echo %computername% %date%