Question : Batch file to "net use" and capture output to a text file

I'm running the following program on WinNT4 machine although I belive this also happens on w2k systems as well.

@ECHO OFF
ECHO Demapping drive ... >> COMMS.LOG
NET USE K: /DELETE /YES >> COMMS.LOG

but when I run this batch file I get a "1" add before the ">>" on lines 2 and 3, line 2 seems to run fine but line 3 dumps it's output to the screen rather than COMMS.LOG

when I run program with @ECHO off REM'ed out I get the follwoing output to the screen.

C:\STUFF>rem @ECHO OFF

C:\STUFF>ECHO Demapping drive ...  1>>COMMS.LOG

C:\STUFF>NET USE K: /DELETE /YES  1>>COMMS.LOG

What causes these the "1" to appear and how can I get round it/fix it ??

Answer : Batch file to "net use" and capture output to a text file

The 1 is the device number for the standard output device. The default STDOUT device is the console (CON). The NET USE command will output to that device if it successful. If it is unsuccessful it will generate output to the standard error device, device number 2. The default STDERR device is also the console. If you want to capture both output devices and append them to your log file you might try this:

C:\STUFF>NET USE K: /DELETE /YES 2>>1>>COMMS.LOG

Good Luck,
Steve
Random Solutions  
 
programming4us programming4us