[英]Can't run console program in batch file
i have a little command line named run.bat 我有一个名为run.bat的命令行
Which is i want change my IP Address setting with command like this 我想用哪个命令更改我的IP地址设置
run.bat
运行
:: netsh interface ipv4
netsh
interface
ip
:: Change ip address
set address "Ethernet" static 192.168.30.77 255.255.255.0 192.168.30.2
the command worked as my expected when i type at CMD directly, but not worked when i put it in run.bat and i sure i have run it with administrator access 当我直接在CMD上键入命令时,该命令按我的预期工作,但是当我将其放入run.bat并确定我已经以管理员权限运行时,该命令不起作用
it works at command line, because you start netsh
(see how the prompt changes) and then directly interact with the netsh
program (you should exit
it finally). 它在命令行中有效,因为您启动了
netsh
(请参阅提示如何更改),然后直接与netsh
程序进行交互(您应该最终exit
它)。 It doesn't work in batchfile, because it executes the first command netsh
- and waits until it's finished (which will happen, when you type exit
). 它不会在批处理文件工作,因为它执行的第一个命令
netsh
-和等待,直到它完成(这会发生,当你键入exit
)。 Then your batchfile tries to execute the next line, but ip
is not a valid command... 然后您的批处理文件尝试执行下一行,但是
ip
不是有效的命令...
But there is also a "direct mode" for netsh
: just enter in one line: netsh interface ip set address "Ethernet" static 192.168.30.77 255.255.255.0 192.168.30.2
(works both in batchfiles and on command line) 但是
netsh
也有一个“直接模式”:只需输入一行即可: netsh interface ip set address "Ethernet" static 192.168.30.77 255.255.255.0 192.168.30.2
(在批处理文件和命令行中均可)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.