Question Locked

how to use redirects ">" in batch

0 helpful
6 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

When using > or >> in a batch file I dont get the result I want.

For instance: ipconfig >> "C:\Documents and Settings\jbusby\My Documents\logs\ipconfig.txt"
saved as ipconfig.bat and run from cmd will append the batch file's contents to the aforementioned file endlessly, rather than just redirect the results of command ipconfig.

I have the same problem with redirecting the results of a FOR command to a txt file.

I noticed that it adds a 1 in the front of the redirect symbols (ie it reads " 1>> ")

Is there a symbol I should be using with the redirects since this is a batch file?

6 replies

by Member 25348569

Don't call the batch file "Ipconfig.bat" as it will keep calling itself! Give it another name or specify the file extension - i.e. ipconfig.exe >> "c:\Doc...etc.

DOS looks for extensions in the order .COM, .EXE, .BAT but searches the local folder first before traversing the Path. Because ipconfig.exe is in Windows\System32, it never gets called as the batch file climbs up its own arse.

Other than that, you shouldn't have any issues with redirection. Works OK for me.

The redirector 1>> will output the standard Output" and 2>> will output the Standard Error in NT. But they aren't really necessary unless you want to get extra clever.

Neil :)

by knowledgebased

I cant believe I made that mistake. It was the end of the day and I was rushed, so thats my excuse

This discussion is closed to new replies.