Technical Information
asked on
batch file to report outcome to a text file
Hi all,
How would I get the below batch file to report outcome to a text file
echo off
net use P: /delete /yes
taskkill /F /IM explorer.exe & start explorer
TIMEOUT 15
net use P: \\(servername)\personnel\% username% /persistent:yes
How would I get the below batch file to report outcome to a text file
echo off
net use P: /delete /yes
taskkill /F /IM explorer.exe & start explorer
TIMEOUT 15
net use P: \\(servername)\personnel\%
ASKER
Thank you but its still not reporting. Is that still a .bat?
And of course if you already have a BAT file, and don't want to alter it, you can capture the output when you run it from a command line by doing:
myscript.bat >"C:\Temp\test.log" 2>&1
»bp
myscript.bat >"C:\Temp\test.log" 2>&1
»bp
Thank you but its still not reporting. Is that still a .bat?Yes, that was still a BAT file, just a couple of enhancements to what you posted.
When you say it's not reporting, did it display anything in the console window?
For testing run it from a new command window so you can see the output on screen.
»bp
ASKER
Bill that worked,
What i want it to capture is the username and successfully ran. Is that possibe?
What i want it to capture is the username and successfully ran. Is that possibe?
Yes, that's still a batch file.
Can't reproduce; how are you deploying this?
Tested with the exact script (which will obviously run into errors)::
Can't reproduce; how are you deploying this?
Tested with the exact script (which will obviously run into errors)::
C:\Temp>type log.cmd
@echo off
(
net.exe use P: /delete /yes
taskkill.exe /F /IM explorer.exe & start explorer
timeout.exe 15
net.exe use P: \\servername\personnel\%username% /persistent:yes
) >"C:\Temp\test.log" 2>&1
C:\Temp>log.cmd
C:\Temp>type test.log
The network connection could not be found.
More help is available by typing NET HELPMSG 2250.
SUCCESS: The process "explorer.exe" with PID 2412 has been terminated.
Waiting for 15 seconds, press a key to continue . 0
System error 53 has occurred.
The network path was not found.
C:\Temp>
For additional output, you can just add some "echo" commands:
@echo off
(
echo Script started by %username% at %Date% %Time%
net.exe use P: /delete /yes
taskkill.exe /F /IM explorer.exe & start explorer
timeout.exe 15
net.exe use P: \\servername\personnel\%username% /persistent:yes
echo Script ended at %Date% %Time%
) >"C:\Temp\test.log" 2>&1
You could do something like this to reduce output to the "log" file.
»bp
echo off
net use P: /delete /yes
taskkill /F /IM explorer.exe & start explorer
TIMEOUT 15
net use P: \\(servername)\personnel\%username% /persistent:yes
if exist P: (
echo %USERNAME% - SUCCESS
) else (
echo %USERNAME% - FALIURE
)
»bp
ASKER
Thanks Bill but the log file isnt in the above script
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Boom - Exactly what I'm looking for sir!
Great, glad that helped.
»bp
»bp
Open in new window