AutoHotKey 运行 Windows 命令

Jak*_*eIC 6 windows autohotkey command-line

有没有办法在 AutoHotKey 中运行 Windows 命令行命令,而无需打开命令提示符并发送按键?

我想运行隐藏在后台的命令。例如

del C:\Users\Test\Desktop\test.txt

我知道 AutoHotKey 中有一个删除文件命令,但我希望能够运行其他在 AHK 中不起作用的命令行命令。那只是一个例子。

谢谢!

Sha*_*yan 9

您不必按照其他答案的%ComSpec%指示使用。您可以使用和使用which是命令指示符,它将在cmd内运行它前面的任何内容。cmd.exe/c

Run cmd.exe /c del C:\Users\Test\Desktop\test.txt

它的语法如下:

Run, Target, WorkingDir, Options, OutputVarPID

RunWait, Target, WorkingDir, Options, OutputVarPID

如果您需要命令完成然后继续,请使用RunWait。要保存命令的输出,例如,如果您想将 WAN IP 地址保存在剪贴板中,您可以使用该命令通过管道传输输出clip

RunWait, cmd.exe /c nslookup myip.opendns.com resolver1.opendns.com | clip
Run Code Online (Sandbox Code Playgroud)

如果您需要一行答案,可以使用以下find命令删除不需要的行:

RunWait, cmd.exe /c nslookup myip.opendns.com resolver1.opendns.com | find /i "address" | find /v "208.67.222.222" | clip
Run Code Online (Sandbox Code Playgroud)

您可以使用以下选项隐藏 cmd 窗口hide

Run cmd.exe /c del C:\Users\Test\Desktop\test.txt,,hide


https://www.autohotkey.com/docs/commands/Run.htm


fis*_*ils 7

run, %comspec% /c del C:\Users\Test\Desktop\test.txt,,hide
Run Code Online (Sandbox Code Playgroud)

%comspec% 指向 cmd.exe 如果您需要以管理员身份运行,您将需要查看 runas。