Sign in to follow this  
Followers 0
Bokkie

DOS command execution and displayed window.

6 posts in this topic

#1 ·  Posted (edited)

Here's the code I'm executing:

local $command = @ComSpec & " /c " & Chr(34) & $filename & Chr(34)
RunWait($command)
FileDelete($pathname)

The command variable contains a string that runs a script against an SQL MSDE database. The script runs without a problem. Now, take a look at the attached screenshot that shows the DOS window that I launch using RunWait. As you can see, there is nothing displayed in the window. My command runs Microsoft's oslq.exe utility and is given an input file to read from and output file to write to. In effect all I/O takes place between files so there is nothing to display! As I point out in the screenshot, it could take a minute to run the command but with no echo in the window it's possible someone might close the command window thinking it has hung up for some reason. I know, I nearly did this myself. I'm trying to find a solution to this problem.

What I had in mind was to launch the command using Run and telling it to hide the window. That way I get immediate control back in my script. But not knowing how long the command window could take to execute makes it tricky (with my limited knowledge of AutoIT) to be able to synchronise my script with the running command. I thought the ProgressOn and ProgressSet calls would help and I think they will.

I could set the progress bar to run for say two minutes and increment the ProgressSet every second or so. But how would I know when the command window has exited? It's a vanilla-flavoured DOS command window. If I put my progress bar updates in a loop and sleep for one second each time, how would I know when the command window has closed so that I can exit the loop and call ProgressOff?

Another possible problem is what happens if the user has another DOS command window open? If I launch another one, how would I know which one is the right one to look for?

Edit: Something else to ponder. If I use Start -> Programs -> Run and enter cmd, the title of the window is C:\Windows\System32\cmd.exe. Could this window title be different on other Windows operating systems? I mention this just in case it's important.

Edited by Peter Hamilton-Scott

Share this post


Link to post
Share on other sites



RunWait

--------------------------------------------------------------------------------

Runs an external program and pauses script execution until the program finishes.

RunWait ( "filename" [, "workingdir" [, flag]] )

Parameters

filename The name of the executable (EXE, BAT, COM, PIF) to run.

workingdir [optional] The working directory.

flag [optional] The "show" flag of the executed program:

@SW_HIDE = Hidden window

@SW_MINIMIZE = Minimized window

@SW_MAXIMIZE = Maximized window

Return Value

Success: Returns the exit code of the program that was run.

Failure: Depends on RunErrorsFatal; see Remarks.

So: (Using your provided code)

local $command = @ComSpec & " /c " & Chr(34) & $filename & Chr(34)
RunWait($command, "", @SW_HIDE)
FileDelete($pathname)

#)

Share this post


Link to post
Share on other sites

Also, your progress bar thing...

(Double-posting ONLY for clarity)

Run

--------------------------------------------------------------------------------

Runs an external program.

Run ( "filename" [, "workingdir" [, flag[, standard_i/o_flag]]] )

Parameters

filename The name of the executable (EXE, BAT, COM, or PIF) to run.

workingdir [optional] The working directory.

flag [optional] The "show" flag of the executed program:

@SW_HIDE = Hidden window

@SW_MINIMIZE = Minimized window

@SW_MAXIMIZE = Maximized window

standard_i/o_flag [optional] Provide a meaningful handle to one or more STD I/O streams of the child process.

1 ($STDIN_CHILD) = Provide a handle to the child's STDIN stream

2 ($STDOUT_CHILD) = Provide a handle to the child's STDOUT stream

4 ($STDERR_CHILD) = Provide a handle to the child's STDERR stream

Return Value

Success: The PID of the process that was launched.

Failure: Depends on RunErrorsFatal; see Remarks.

Failure: Sets @error to -1 if EOF is reached, STDOUT was not redirected for the process or other error.

local $command = @ComSpec & " /c " & Chr(34) & $filename & Chr(34)
Run($command, "", @SW_HIDE)
while 1
   $line = StdoutRead($foo)
   If @error = -1 Then 
      ExitLoop;;End of Stream (program finish)
   EndIf
wend
FileDelete($pathname)

#)

Share this post


Link to post
Share on other sites

During the time you were posting I did try @SW_HIDE and that works. I was thinking also that a quick and dirty solution would be to change the mouse pointer to an hourglass then execute the RunWait and when it returns change the mouse pointer back to its normal type.

Is there a function to do that? Something like this pseudocode:

SetMousePointer(hourglass)
RunWait($command, "", @SW_HIDE)
SetMousePointer(normal)

Share this post


Link to post
Share on other sites

GUISetCursor

--------------------------------------------------------------------------------

Sets the mouse cursor icon for a GUI window.

GUISetCursor ( [cursorID [, override [, winhandle]]] )

Parameters

cursorID [optional] Cursor Id (See Remarks).

override [optional] Force the requested cursor even when over controls (see below).

0 = (default) Don't override a control's default cursor.

1= override control's default cursor.

winhandle [optional] Windows handle as returned by GUICreate (default is the previously used Window).

Return Value

Success: Returns 1.

Failure: Returns 0.

Remarks

If the cursorID is invalid the standard arrow will be displayed.

Usually when you move the cursor over an edit control or other control the cursor changes shape. The "override" option allows you to force the requested cursor to be shown at all times. Note: If you have changed a controls cursor with GUICtrlSetCursor then this control cursor will always be shown.

For a list of valid cursor IDs see MouseGetCursor.

CursorId = 16 will hide the cursor.

GUISetCursor(15, 1)

;;;;; DO STUFF

GUISetCursor()

#)

Share this post


Link to post
Share on other sites

Thanks a million nfwu.

I ended up with a belt-and-braces approach. I set the cursor to the hourglass as you described and I also output some text to a status label at the bottom of the form. Works 100%. :)

local $command = @ComSpec & " /c " & Chr(34) & $command & Chr(34)
GUICtrlSetData($p_status, "Running. Please wait...")
GUISetCursor($IDC_WAIT, 1)
RunWait($command, "", @SW_HIDE)
GUISetCursor()
GUICtrlSetData($p_status, "")

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