如何使用AutoIt(* .au3)脚本在CMD窗口中发出命令?

时间:2013-06-07 08:32:51

标签: cmd autoit

我尝试过但没有工作:

  1. 我打开了cmd.exe
  2. 键入" cd \" >>没有引号
  3. 输入
  4. 键入" cd C:\ Program Files(x86)\ Jenkins"
  5. 输入
  6. 键入" jenkins.exe启动"
  7. 输入
  8. 我还在每种类型之后使用sleep命令,只是为了确保它不会因快速执行而跳过。

    ;Run application
    Run("cmd.exe")
    
    ;Wait for CMD to be opened
    WinWaitActive("Administrator: C:\Windows\system32\cmd.exe", "", 15)
    
    ;Write some commands on cmd
    ControlSend("Administrator: C:\Windows\system32\cmd.exe", "", "Edit1", "cd\")
    Sleep(10000)
    Send("{Enter}")
    Sleep(10000)
    ControlSend("Administrator: C:\Windows\system32\cmd.exe", "", "Edit1", "cd C:\Program Files (x86)\Jenkins")
    Sleep(10000)
    Send("{Enter}")
    ControlSend("Administrator: C:\Windows\system32\cmd.exe", "", "Edit1", "jenkins.exe start")
    Sleep(10000)
    Send("{Enter}")
    

    我得到了答案:

    ControlSend("Administrator: C:\Windows\system32\cmd.exe", "", "", "cd C:\Program Files (x86)\Jenkins")
    

    我需要删除"编辑" ,因为cmd不是可编辑的窗口。

4 个答案:

答案 0 :(得分:6)

直接启动您的计划:

RunWait(@ComSpec & " /c jenkins.exe start", "C:\Program Files (x86)\Jenkins")

答案 1 :(得分:1)

使用&

Exp:

$CMD = 'cd %tmp% & md 1 & md 2 & cd %tmp%/1 & md 3 4 & md "5 6" &'
RunWait(@ComSpec & " /c " & $CMD )

答案 2 :(得分:0)

Run("C:\WINDOWS\system32\cmd.exe")
WinWaitActive("C:\WINDOWS\system32\cmd.exe")
send('cd C:\Program Files (x86)\' & "{ENTER}")

答案 3 :(得分:0)

;Run application
Run("cmd.exe")

;Wait for CMD to be opened
WinWaitActive("Administrator: C:\Windows\system32\cmd.exe", "", 1)
Send('C:' & "{ENTER}")
Send('cd Program Files (x86)' & "{ENTER}")
Send('cd TestAPP' & "{ENTER}")
Send('start testApp.exe' & "{ENTER}")