Sign in to follow this  
Followers 0
Jdavis

Running successive commands in the same cmd window?

7 posts in this topic

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.

Share this post


Link to post
Share on other sites



You can also create a BAT script and then run it. :)


When the words fail... music speaks

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

I appreciate that, but I think it's somewhat more complicated because what I need to run are executables that take a few seconds to run before they're through.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

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

Share this post


Link to post
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
Sign in to follow this  
Followers 0