Jump to content
Sign in to follow this  
VeeDub

Error with RunWait

Recommended Posts

VeeDub

Hello,

I'm having an issue with the following statement:

$PID = RunWait(@ComSpec & " /k " & """C:\Program Files\ECIClientV6\StartClient.bat""")

When I run the script the command prompt reports the following:

'C:\Program' is not recognized as an internal or external command,
operable program or batch file.

So it looks like the issue is with the declaration of the program path. I am pretty sure that I should be using 3 quotes on each side of the string, but I'm not having much luck looking for info on declaring variables ... and maybe that's not the issue anyway.

Would appreciate some suggestions of things to try.

Thanks

VW

Share this post


Link to post
Share on other sites
xXlowXx

$PID = RunWait(@ComSpec & " /k " & '"C:\Program Files\ECIClientV6\StartClient.bat"')

Parameter with strings need to be surrounded by Quotes

Edited by xXlowXx

Share this post


Link to post
Share on other sites
VeeDub

Hi xXlowXx,

Unfortunately that made no difference.

I have been testing the code on a different computer - with no change in behaviour.

I tried your idea there.

$ECI_Path = '"C:\Program Files (x86)\ECIClientV6\StartClient.bat"'
ConsoleWrite("ECI Path: " & $ECI_Path & @CRLF)
$PID = RunWait(@ComSpec & " /k " & $ECI_Path)

The command prompt reports:

The system cannot find the path specified

I have copied and pasted the path from the ConsoleWrite command into a command prompt and it goes to the correct directory. The path and filename are definitely correct.

I think there may be a bug here. As a test I created a batch file in a path where there is no space in the path and that bat file runs fine. But when I try and run a bat file where there is a space in the path then it doesn't work.

As a work-around I tried copying the startclient.bat file to the location of the script and changed some of the arguments in the batch file to use the full path rather than relative. Unfortunately while the bat file attempts to start it bombs out.

Share this post


Link to post
Share on other sites
VeeDub

For someone who happens to come across this post in the future. The issue here seems to be a quirk with cmd.exe. If I paste the full path to the bat into a command prompt, the behaviour is the same. The 'issue' is the way that cmd.exe processes the argument - not AutoIt.

I'll have to change the code to change to the directory where the bat file is located and issue the command from there.

Share this post


Link to post
Share on other sites
VeeDub

I found that the code changes (to interact with the command prompt) were more involved than I expected.

This code is based on an excellent example by Iron

#include <Misc.au3>
#include <Constants.au3>
if _Singleton("Start_ECIClient",1) = 0 Then
Msgbox(48,"ECI Client","The ECI Client is currently in use, please try again later.")
Exit
Else
; current working directory
consoleWriteLn( "WorkingDir = " & @WorkingDir )
Console("c:")
Console("cd\")
Console("cd Program Files")
Console("cd ECIClientV6")
; current working directory
consoleWriteLn( "WorkingDir = " & @WorkingDir )
; Start ECI Client
$PID = RunWait(@ComSpec & " /c " & "StartClient.bat")
EndIf

Func Console( $prompt )
;check for "cd\" to change WorkingDir
If StringInStr( $prompt, "cd\", 1 ) Then
$prompt = StringTrimLeft( $prompt, 2 )
Local $newDir = StringLeft( @WorkingDir, 2 ) & $prompt
consoleWriteLn( $newDir )
If FileChangeDir( $newDir ) Then
consoleWriteLn( "new_WorkingDir = " & @WorkingDir )
Return 1
Else
consoleWrite( "Fault" & @CRLF )
EndIf
;check for "cd " to change WorkingDir
ElseIf StringInStr( $prompt, "cd ", 1 ) Then
$prompt = StringTrimLeft( $prompt, 3 )
Local $newDir = @WorkingDir & "\" & $prompt
consoleWriteLn( $newDir )
If FileChangeDir( $newDir ) Then
consoleWriteLn( "new_WorkingDir = " & @WorkingDir )
Return 1
Else
consoleWrite( "Fault" & @CRLF )
EndIf
;check for "?:" to change Drive
ElseIf StringRegExp( $prompt, "\A[[:alpha:]]:", 0 ) Then
consoleWriteLn( "Patern funst :) " & @WorkingDir )
$prompt = StringLeft( $prompt, 2 )
If FileChangeDir( $prompt ) Then
consoleWriteLn( "new_WorkingDir = " & @WorkingDir )
Return 1
EndIf
Else
Local $foo = Run(@ComSpec & " /c " & $prompt, @WorkingDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
Local $line
While 1
$line &= StdoutRead($foo)
If @error Then ExitLoop
Wend
While 1
$line &= StderrRead($foo)
If @error Then ExitLoop
WEnd
consoleWriteLn( $line )
EndIf
Return 0
EndFunc
Func consoleWriteLn( $d )
consoleWrite( $d & @CRLF )
Return $d
EndFunc

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  

×