Jump to content

Running successive commands in the same cmd window?


Jdavis
 Share

Recommended Posts

Admittedly, I haven't done a lot of testing on this on my own before posting.

There's a series of commands I'm sending to a command window, but it seems inefficient to do Run( @ComSpec ... ) for every command I want to send since I don't want to open a bunch of command windows. Likewise, it doesn't seem quite right using Send() to send all my commands to the active window.

Are these my most valid options? I thought there may be a way to just open one command window via Run( @ComSpec) and then use successive Run() commands to run the executables/commands inside the previously opened command window.

I hope that didn't sound needlessly complicated.

Link to comment
Share on other sites

Yeah, I was going to go the batch file route if I couldn't find a more AutoIt exclusive solution.

AutoItSetOption('WinTitleMatchMode',2)
Run('cmd',@SystemDir,@SW_HIDE)
WinWait("cmd.exe")
WinActivate("cmd.exe")
WinWaitActive('cmd.exe')
Send('cd C:' & @CRLF)
Send('ver' & @CRLF)
Send ('doskey /HISTORY' & @CRLF)
WinSetState("cmd.exe","",@SW_SHOW)
Sleep(7500)
ProcessClose("cmd.exe")

When the words fail... music speaks.

Link to comment
Share on other sites

RunWait() ?

Or maybe what I often do to add a timeout...

$run_dos_pid = Run()
        $flag_run_dos_timestamp = TimerInit()
        
        While 1
            If TimerDiff($flag_run_dos_timestamp) > 5000 Then
                ProcessClose($run_dos_pid)
                ExitLoop
            EndIf
        Wend

If the exes produce and output maybe add an FileExist check to the loop to exit it... or even better a check against file-usage with _FileInUse() (http://www.autoitscript.com/forum/index.php?showtopic=85339&view=findpost&p=613340)?

Edited by KaFu
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...