pcalvert Posted March 8, 2007 Share Posted March 8, 2007 I am trying to write a batch file that will run netstat and send the output to a text file. Here is what I tried:netstat -an > "C:\My Documents\netstat-out.txt"pauseI tried this on Windows 98 SE and it doesn't work. When I execute the batch file (netstat.bat), the command scrolls across the screen (inside the MS-DOS window) repeatedly, and I have to close the MS-DOS window instead of letting the batch file finish. And although the output file netstat-out.txt was created, it is a zero-byte file with nothing in it.Call anyone tell me why this doesn't work?Phil Link to comment Share on other sites More sharing options...
IcemanND Posted March 8, 2007 Share Posted March 8, 2007 my guess would be you named your batch file netstat.bat, so the batch file is calling itself instead of running netstat. Link to comment Share on other sites More sharing options...
tap52384 Posted March 8, 2007 Share Posted March 8, 2007 i thought it required two greater than signs (>>); I could be wrong... Link to comment Share on other sites More sharing options...
soporific Posted March 8, 2007 Share Posted March 8, 2007 (edited) I am trying to write a batch file that will run netstat and send the output to a text file. Here is what I I tried this on Windows 98 SE and it doesn't work. When I execute the batch file (netstat.bat), the command scrolls across the screen (inside the MS-DOS window) repeatedly, and I have to close the MS-DOS window instead of letting the batch file finish. And although the output file netstat-out.txt was created, it is a zero-byte file with nothing in it.PhilEDIT: it IS caused by your use of a RESERVED word ... change the name of Netstat.bat to something else and it will work.My original post text - obsolete nowit really should work... does NETSTAT -an work from the command line? i couldn't replicate your problem ... try this code in a bat file:[code]@echo offecho.IF NOT EXIST "C:\My Documents\nul" echo "C:\My Documents" could not be found...IF NOT EXIST "C:\My Documents\nul" echo PAUSEIF NOT EXIST "C:\My Documents\nul" echo goto ENDecho.echo. Now turning off directory protection...rem|choice>NUL /c:c /n /t:c,1ATTRIB -H -S -R "C:\My Documents"echo.echo. Now writing output file...rem|choice>NUL /c:c /n /t:c,1netstat -an> "C:\My Documents\netstat-out.txt"rem|choice>NUL /c:c /n /t:c,1echo.echo. Now turning directory protection back on...rem|choice>NUL /c:c /n /t:c,1ATTRIB +S "C:\My Documents"echo.echo. Now checking that the file exists...rem|choice>NUL /c:c /n /t:c,1IF NOT EXIST "C:\My Documents\netstat-out.txt" goto NOLUCKecho.echo. File was found! Yay!echo.PAUSEgoto END:NOLUCKecho.echo. File was not found... sigh.echo.PAUSE:ENDCLSEXIT Edited March 8, 2007 by soporific Link to comment Share on other sites More sharing options...
pcalvert Posted March 8, 2007 Author Share Posted March 8, 2007 Thanks for help. It figures that it would be something simple like that. The thought actually did cross my mind that I should try renaming my batch file, but for some reason I didn't do it. Phil Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now