Sign in to follow this  
Followers 0
_JP_

Waiting for DOS command

10 posts in this topic

All,

I have a very basic test script that contains: RunWait(@COMSPEC & " /c " & " dir /s", "c:\")

I invoke it as such - c:\tmp>autoit3 test.au3

As expected, there's a new command windows, but I also get back to the c:\tmp prompt before the 'child' windows is done listing the content of my C drive. I thought it was supposed to wait. What am I missing?

Thanks,

JP

P.S. This topic comes up once in a while, but if there was an answer in there, I haven't found it. I'm using version 3.1.1 and I've tried a variety of quotes (single, double, w/ and w/o &, etc.)

Share this post


Link to post
Share on other sites



Hmmm, try using the UDF _RunDos, I think it is is misc.au3???

:)

>_>

:(


[center][/center]Working on the next big thing.Currently Playing: Halo 4, League of LegendsXBL GT: iRememberYhslaw

Share this post


Link to post
Share on other sites

You misunderstand the meaning of the "Wait" in RunWait.

It means to wait before executing the next command in the script.

It simply sound like you don't have a next command.

This...

RunWait(@COMSPEC & " /c " & " dir /s", "c:\temp")
MsgBox(64, "password", "hi", 10)

demonstrates what I mean. The "hi" dialog will not appear until the directory listing is complete.

Understand; if you run any script from the command-line, that's just what you are doing, launching it, and no more. That only takes as long as it takes you to hit <enter>. AutoIt launches, and control is immediately handed back to you.

AutoIt scripts don't run IN a console, they run in the regular window manager, whether they have a GUI or not. They may spawn a console, and then (after waiting or not waiting, depending) do something else, and then something else, and so on, but they don't run IN the console.

In essence, as soon as you hit enter in the console, that's the end of your connection to the AutoIt script. If you really want to actually wait yourself, perhaps get more feedback inside your script, etc., run it from inside your ide (text editor, etc) using the "/ErrorStdOut " switch.

If that still doesn't make sense, post again, and I'll have another crack at it! :)

-mu

Share this post


Link to post
Share on other sites

Are you looking to use the " \k " switch rather than " \c " ?


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

As expected, there's a new command windows, but I also get back to the c:\tmp prompt before the 'child' windows is done listing the content of my C drive. I thought it was supposed to wait. What am I missing?

The command prompt waits for AutoIt3 to finish before the prompt returns active here on XP Pro SP2. So Dir command does it's run before any control is returned. This would be regarded as normal behaviour expected. You may need to use the Start command to get control back immediately to the command prompt, but Start is not used with internal commands as Dir. Edited by MHz

Share this post


Link to post
Share on other sites

[fear1313]

I grep'ed and found _RunDos in Process.au3. It works as described in the comments, but that's not what I was looking for.

[mr. underperson]

Your explanation is as clear as it is depressing and your example drives the point home. I was planning on calling an AutoIt script from an InstallShield (IS) installer. And I really wanted the execution of the installer to wait for the script to be done running. Unfortunately IS can only track processes it spawns itself, not grand children (e.g. the CMD spawned by AutoIt). The moment IS sees the call 'autoit3 myscript.au3' return, it'll move on to its next statement thereby screwing up my event synchronization. Is there another way to fire off my au3 script? I'll have to ponder your /ErrorStdOut suggestion for a bit, I'm not sure I understand.

[smOke_N]

The /k option leaves the child command opened after the DOS command is done running, right? I found it useful for debugging, but it's not what I'm looking for.

[MHz]

Yeah, in the child window you don't get the prompt back until the command (dir) is done running, but you do get control back immediately in the dos box where you invoked autoit3.

Share this post


Link to post
Share on other sites

If you try running calc or notepad directly from the command prompt, you will get back to c:\tmp> before the program has closed.

The only exception is if you have those calls in a batch file. In the example below, notepad will not run until calc is exited. (If notepad.exe is invoked with start, then the batch file won't wait...)

@echo off

calc.exe

start notepad.exe

start mspaint


Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites

CyberSlug, you magnificient bastard, way to go! Indeed, once wrapped in a batch file, my script startup problem appears to be solved (in a dos box anyways).

Thanks a bunch to all.

JP

Share this post


Link to post
Share on other sites

could you use start /wait to launch your stuff?

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Try this:

RunWait(@COMSPEC & " /k " & " dir /s", "c:\")

(whit "/k" switch as SmOke_N mentioned)

Edited by tittoproject

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