Batch file problem...Probably going to feel stupid when someone answers this...

crash331

Member
Sep 26, 2013
57
0
0
I can't figure out what's going wrong here. I am trying to just run a simple batch file that will write the machines IP to a folder with a filename of %computername%.txt.

The command works if I type it in to a command prompt, but when I run it as a batch file, the command gets altered and does not work. I don't know if my knowledge of batch files is to blame or my knowledge of netsh, neither of which is great.

Anyway, here is the command:

Code:
net use W: \\10.11.115.230\config\IPLogs pass /user:user

netsh interface ip show addresses > W:\%computername%.txt



And here is what shows up in the command window:

Code:
net use W: \\10.11.115.230\config\IPLogs pass /user:user

netsh interface ip show addresses 1>W:\configserver.txt


Why does the bracket get a 1 before and a space delete after? I have tried escaping the bracket with ^> but it didn't work.

What simple thing am I missing?
 

code65536

Golden Member
Mar 7, 2006
1,006
0
76
Why does the bracket get a 1 before and a space delete after? I have tried escaping the bracket with ^> but it didn't work.

That's normal. The 1 just means you are redirecting stdout (2 for stderr). The space after the ">" is unimportant.

For example, "command 1>output.txt 2>error.txt" would save the non-error output to output.txt and any error messages to error.txt, and "command 2>nul" suppresses error messages. When you do not specify a 1 or a 2, the system assumes 1; it merely makes that explicit when echoed back during batch execution.

So it's perfectly fine.

And the batch file should work. If it's not working, it's for reasons completely unrelated to the redirect being echoed back more explicitly.
 

crash331

Member
Sep 26, 2013
57
0
0
Ok, that's reassuring. Must be something with net use not giving correct writing permission then.


edit: Yep, that was it. I was just second guessing myself in the wrong area. Thanks!
 
Last edited: