This is an ongoing collection of dos command line tips and tricks I've run across over the years. I tend to forget what I did 5 min ago, let alone a bunch of DOS commands, so I'm collecting the stuff I've found here as a place of reference. Much of what you will find here is probably posted on the internet somewhere (which is where I got it from) or, I've created a few little tricks myself to help me along the way.
Append to New File - This will create OR overwrite the existing file.
dos-program.exe > file.txt
Append to Existing File - This will create OR add to any existing file.
dos-program.exe >> file.txt
Script to add carriage returns to appended file
Note: the following script will overwrite the existing file each time it is run...
@echo off echo Run the fancy program and output to file! dos-program.exe > file.txt echo. >> file.txt echo. >> file.txt dos-program2.exe >> file.txt
get Computer Name Environment Variable
Environment Variable Heaven
Execute DOS Command Scripts / Bat files from UNC Network path - This will automatically map the last available drive letter to the UNC path you currently reside in. Let's say you are in \\computer\folder\test This will automatically map Z:\ to the test folder for you.
@echo off cls pushd %~dp0 echo Do Something cool! popd
Append the Current Time to a File
net time \\%computername% |find "time" > "file.txt"
This will output in the following format:
Current time at \\THISCOMPUTER is 7/26/2010 10:28 AM