Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to give commands in a CMD window using AutoIt (*.au3) scripts?

Tags:

cmd

autoit

What I have tried and didn't work:

  1. I opened cmd.exe
  2. Typed "cd\" >> without quotes
  3. Pressed Enter
  4. Typed "cd C:\Program Files (x86)\Jenkins"
  5. Pressed Enter
  6. Typed "jenkins.exe start"
  7. Pressed Enter

I have also used the sleep command after every type, just to make sure that it is not skipping because of fast execution.

;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}")

I got the answer:

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

I needed to remove "Edit" , as cmd is not an editable window.

like image 466
paul Avatar asked Jun 07 '13 08:06

paul


2 Answers

Start your program directly:

RunWait(@ComSpec & " /c jenkins.exe start", "C:\Program Files (x86)\Jenkins")
like image 142
Obi Avatar answered Oct 02 '22 23:10

Obi


Use &

Exp :

$CMD = 'cd %tmp% & md 1 & md 2 & cd %tmp%/1 & md 3 4 & md "5 6" &'
RunWait(@ComSpec & " /c " & $CMD )
like image 44
ahmeddzcom ahmed Avatar answered Oct 02 '22 22:10

ahmeddzcom ahmed