简体   繁体   English

如何打开cmd.exe并执行命令?

[英]How do I open cmd.exe and execute a command?

So I want to set the system volume to 25% through a batch file. 因此,我想通过批处理文件将系统音量设置为25%。 I managed to open cmd.exe using: 我设法使用以下命令打开cmd.exe:

start cmd

however when I add the command: 但是,当我添加命令时:

start cmd /k echo nircmd.exe setsysvolume 16384

it types it into the cmd window, but doesn't actually execute the command. 它将其输入到cmd窗口中,但实际上并未执行该命令。 It's hard to explain, but it's like the text is written before the command line interface actually begins taking commands. 很难解释,但这就像在命令行界面实际开始接收命令之前编写文本一样。 What results is: 结果是:

nircmd.exe setsysvolume 16834
C:\Users\User\Desktop>

Any ideas what is going on? 有什么想法吗?

echo nircmd.exe setsysvolume 1638 > foo.bat && start cmd /k foo.bat

You also can run it this way 您也可以这样运行

echo nircmd.exe setsysvolume 1638 > foo.bat && start cmd /c foo.bat

so that the new command window closes when foo.bat has finished or just 这样,当foo.bat完成或刚关闭时,新的命令窗口将关闭

echo nircmd.exe setsysvolume 1638 > foo.bat && foo.bat

to run foo.bat directly. 直接运行foo.bat。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM