Sending command to a single in a text file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Ryobi
Posts: 1
Joined: 22 May 2021 13:02

Sending command to a single in a text file

#1 Post by Ryobi » 22 May 2021 13:44

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

OJBakker
Expert
Posts: 90
Joined: 12 Aug 2011 13:57

Re: Sending command to a single in a text file

#2 Post by OJBakker » 23 May 2021 00:43

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

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Sending command to a single in a text file

#3 Post by Squashman » 23 May 2021 22:07

Why not....?

Code: Select all

echo %computername% %date%

Post Reply