Command prompt result to text file

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
Okapi
Junior Coder
Posts: 28
Joined: Wed Dec 29, 2010 1:22 am

Command prompt result to text file

Post by Okapi » Sat May 07, 2011 4:44 pm

Hi all,
I want to execute 3 commands in command prompt to retrieve some info and get the results of them one under the other in the same txt file. Syntax of commands are :

Code: Select all

//computer info
systeminfo

//drive letters
wmic logicaldisk get caption,providername,drivetype,volumename

//account type
net user %USER_NAME%
I'm confused on how to do that, can anyone help ? thanks.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Sun May 08, 2011 8:14 am

Pipe to a text file.

E.g.:

Code: Select all

//run the command, piping the results to a file
Let>RP_WAIT=1
Run>cmd.exe /c ""c:\windows\system32\systeminfo.exe" >> "%TEMP_DIR%sysinfo.txt""

//read the file into memory
ReadFile>%TEMP_DIR%sysinfo.txt,systext

//delete the temp file
DeleteFile>%TEMP_DIR%sysinfo.txt

//Display the contents in a message box
MessageModal>systext
An understanding of "DOS" commands and piping output to a file (the >> filename) bit helps and there are lots of examples on these forums of this kind of thing.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts