简体   繁体   English

运行命令和cmd中的命令有什么区别?

[英]What's the difference between Run command and commands in cmd?

I have the following script: 我有以下脚本:

^!c::
Run stop
Return

Stop is configured to run a program via environment variables. 将Stop配置为通过环境变量运行程序。

So if I open up cmd and type “stop” and hit enter the program opens as intended, even if I push winkey + R it does the same thing. 因此,如果我打开cmd并键入“ stop”,然后按Enter输入程序将按预期方式打开,即使我按winkey + R也会执行相同的操作。 However if I use the script with ctrl + alt + c . 但是,如果我将脚本与ctrl + alt + c一起使用 I do not get the same result. 我没有得到相同的结果。

Why is the script doing something different? 为什么脚本会做一些不同的事情?

How can I change my script to behave the same way as if it was typed into cmd or winkey + R ? 如何更改脚本,使其行为与键入cmd或winkey + R时的行为相同?

Simple : 简单

run, %comspec% /c stop

Or if this doesn't work you could just start a cmd window and send it directly 或者,如果这不起作用,您可以启动一个cmd窗口并直接发送

run, %comspec% /k
WinWait, %comspec%
WinActivate
Send stop{Enter}

/c tells the console window to close after execution, /k lets it stay open /c告诉控制台窗口在执行后关闭, /k使其保持打开状态

or you could use an COM object and even get the output. 或者您可以使用COM对象甚至获得输出。

objShell := ComObjCreate("WScript.Shell")
objExec := objShell.Exec(ComSpec " /c stop")

strStdOut := ""
while, !objExec.StdOut.AtEndOfStream
{
    strStdOut := objExec.StdOut.ReadAll()
}

Update: Without the run command at all: 更新:完全没有运行命令:

SetTitleMatchMode, 2

send #r

WinWait, TITLE_OF_THE_RUN_WINDOW
WinActivate

send cmd{Enter}

WinWait, cmd.exe
WinActivate

WinGetTitle, title
Send stop{Enter}

WinWait, %title%,,, stop
WinClose,

TITLE_OF_THE_RUN_WINDOW replace this with the title of the window, which opens on Win+r. TITLE_OF_THE_RUN_WINDOW替换为在Win + r上打开的窗口的标题。 A windows cmd window has the command in its title while it gets executed. Windows cmd窗口在执行时在其标题中带有命令。 So we save the title of the command window, and wait for it to drop the command ("stop") and close it then. 因此,我们保存了命令窗口的标题,然后等待它放下命令(“停止”)并关闭它。

UPDATE: Cmd window close added to solution 4 更新:Cmd窗口关闭已添加到解决方案4

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

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