Problem with WScript.Shell.ExecScript() Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
sancarn
Posts: 224
Joined: 01 Mar 2016, 14:52

Problem with WScript.Shell.ExecScript()

27 Mar 2017, 17:26

I have a problem with this code. I'm not entirely sure why it is occurring...

Code: Select all

#SingleInstance, off
if A_IsCompiled {
	s:=Cmd("""" A_ScriptFullPath """ ""Match"" """ Match_TableName """ """ Match_inCol """ """ Match_outCol """ """ Match_needle """ """ Match_options """ """ Match_mNum """ """ Match_sNum """")
	msgbox, %s%
} else {
	command := """" A_AhkPath """ """ A_ScriptFullPath """ ""Match"" """ Match_TableName """ """ Match_inCol """ """ Match_outCol """ """ Match_needle """ """ Match_options """ """ Match_mNum """ """ Match_sNum """"
	msgbox, %command%
	s:=Cmd(command)
	msgbox, %s%
}

;...

Cmd(command){
	x := ComObjCreate("WScript.Shell").Exec("cmd.exe /q /c " command)
	return % "STDOut: " x.StdOut.ReadAll() "`nSTDErr: " x.StdErr.ReadAll()
}
When I run the above code I see that command is:

Code: Select all

"C:\Program Files\AutoHotkey\AutoHotkey.exe" "U:\Macros\3_AHK\MapInfo Regex\MapInfoRegex-master\MI_RegexEngine.ahk" "Match" "AL_Extracty" "Bob" "Field100" "" "" "*" "*"
When cmd() runs this command it returns this:

Code: Select all

STDOut: 
STDErr: 'C:\Program' is not recognized as an internal or external command, operable program or batch file.
On the other hand if I go to cmd.exe and run the same command the program runs as expected...

Has anyone got any idea why this may be occurring?
qwerty12
Posts: 468
Joined: 04 Mar 2016, 04:33
Contact:

Re: Problem with WScript.Shell.ExecScript()  Topic is solved

28 Mar 2017, 12:15

You apparently need another pair of quotes around the command for cmd /c to treat the command as one, well, command:

command := """" """" A_AhkPath """ """ A_ScriptFullPath """ ""Match"" """ Match_TableName """ """ Match_inCol """ """ Match_outCol """ """ Match_needle """ """ Match_options """ """ Match_mNum """ """ Match_sNum """" """"
sancarn
Posts: 224
Joined: 01 Mar 2016, 14:52

Re: Problem with WScript.Shell.ExecScript()

28 Mar 2017, 13:48

That is totally random... :P Fortunately, in this instance, I could completely bypass the issue, but this will help a lot regardless.

Thanks! :)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, mikeyww, scriptor2016 and 263 guests