My Idea is to Launch a PureBasic EXE and use a command line Parameter to pass the script via a Temporary File.
Inside this EXE it opens to file parses the individual script lines, so here is the question: is there some magical way to execute these lines of code?
Here's the code so far....
Code: Select all
Procedure CheckCmdLineParms()
Protected X, K, Result, CmdLine$, Path$, Name$, Script$, Format
Result = CountProgramParameters()
If Result = 1
NewList ScriptLine.s()
CmdLine$ = ProgramParameter(0)
Path$ = GetPathPart(CmdLine$)
Name$ = GetFilePart(CmdLine$)
If FileSize(CmdLine$) > 1
OpenFile(6, CmdLine$)
Format = ReadStringFormat(0)
While Eof(6) = 0
Script$ = ReadString(6, Format)
Wend
CloseFile(6)
EndIf
K = CountString(Script$, #LF$)
For X = 1 To K+1
AddElement(ScriptLine())
ScriptLine() = StringField(Script$, X, #LF$)
Next
FreeList(ScriptLine())
EndIf
EndProcedure
Code: Select all
AUTOIT::Run("C:\Windows\System32\notepad.exe", "C:\Windows\System32\", 1)
AUTOIT::WinWait("Untitled - Notepad", "")
Delay(2000)
AUTOIT::AutoItSetOption("MouseCoordMode", 0)
Delay(500)
AUTOIT::MouseClick("left", 614, 50, 1)
Delay(500)
AUTOIT::MouseClick("left", 16, 14, 1)
Delay(500)
I've also considered using the code which generates the script to alternatively execute it...which would be considerably easier than the other option...BUT then I'm NOT really running or testing the script
A third option would be to Generate code and insert code into a pre-created PureBasic project. And then launch the PB Compiler to Compile and execute the script, then run a cleanup step resetting the project back to Zero ready for next test. This has my current vote, but it's a lot of moving parts, and a lot of "stuff" to laydown with an install, where it can be modified, compiled, and executed...could be problematic with virus protection and permissions
In the old days, FoxPro had a parameter to add to a variable containing code to execute it! Java code can be retrieved from DB Queries and executed. I don't suppose PureBasic has a similar feature?
It's just a pain to continuously jump between the Script Creator and the Script Runner, even if it IS the safest answer...
--------------------------------------------------------
After further work on this, See code. This compiles. it May be "A" Solution.
It allows for up to 10 Fields/Parameters...It's just going to be one huge If..ElseIf......EndIf
Code: Select all
;========================================================
;==== AutoItX Script Testing
;====
;==== Author: Pete Hollyer
;====
;==== Notes: If EXE is called with CMDLine of Script
;==== Run Script
;====
;========================================================
Procedure ParseParams(Vars$, Array Fields.s(1) )
Protected X, K, Y, Var$, Piece$
Vars$ = ReplaceString(Vars$, "(", "")
Vars$ = Trim(ReplaceString(Vars$, ")", ""))
; "C:\Windows\System32\notepad.exe", "C:\Windows\System32\", 1
K = CountString(Vars$, ",")
For X = 1 To K +1
Piece$ = Trim(StringField(Vars$, X, ","))
;If String...
If CountString(Piece$, Chr(34)) = 2
Fields(K) = ReplaceString(Piece$, Chr(34), "")
Else
Fields(K) = Piece$
EndIf
Next
For Y = K+1 To 10
Fields(Y)=""
Next
EndProcedure
Procedure CheckCmdLineParms()
Protected X, K, Result, CmdLine$, Path$, Name$, Script$, Cmd$, Vars$, Line$
Result = CountProgramParameters()
If Result = 1
NewList ScriptLine.s()
CmdLine$ = ProgramParameter(0)
Path$ = GetPathPart(CmdLine$)
Name$ = GetFilePart(CmdLine$)
If FileSize(CmdLine$) > 1
ReadFile(6, CmdLine$)
While Eof(6) = 0
Script$ = Script$ + ReadString(6)
Wend
CloseFile(6)
EndIf
K = CountString(Script$, #LF$)
For X = 1 To K+1
AddElement(ScriptLine())
ScriptLine() = StringField(Script$, X, #LF$)
Next
For X = 0 To ListSize(ScriptLine())-1
SelectElement(ScriptLine(), X)
If Len(Trim(ScriptLine())) < 1
Continue
EndIf
Dim Fields.s(10)
Line$=Trim(ScriptLine())
Debug Line$
Cmd$ = StringField(Line$, 1, "(")
Vars$ = StringField(Line$, 2, "(")
If Cmd$="Delay"
Vars$ = ReplaceString(Vars$, "(","")
Vars$ = ReplaceString(Vars$, ")","")
Delay(Val(Vars$))
Else
ParseParams(Vars$, Fields())
If Cmd$ = "AUTOIT::Run"
; "C:\Windows\System32\notepad.exe", "C:\Windows\System32\", 1
AUTOIT::Run(Fields(1), Fields(2), Val(Fields(3)))
EndIf
EndIf
Next
FreeArray(Fields())
FreeList(ScriptLine())
EndIf
EndProcedure
Code: Select all
;========================================================
;==== AutoItX Script Testing
;====
;==== Author: Pete Hollyer
;====
;==== Notes: If EXE is called with CMDLine of Script
;==== Run Script
;====
;========================================================
Procedure ParseParams(Vars$, Array Fields.s(1) )
Protected X, K, Y, Var$, Piece$
Vars$ = ReplaceString(Vars$, "(", "")
Vars$ = Trim(ReplaceString(Vars$, ")", ""))
; "C:\Windows\System32\notepad.exe", "C:\Windows\System32\", 1
K = CountString(Vars$, ",")
For X = 1 To K +1
Piece$ = Trim(StringField(Vars$, X, ","))
;If String...
If CountString(Piece$, Chr(34)) = 2
Fields(X) = ReplaceString(Piece$, Chr(34), "")
Debug Fields(X)
Else
Fields(X) = Piece$
EndIf
Next
For Y = X+1 To 10
Fields(Y)=""
Next
EndProcedure
Procedure CheckCmdLineParms()
Protected X, K, Result, CmdLine$, Path$, Name$, Script$, Cmd$, Vars$, Line$
Result = CountProgramParameters()
If Result = 1
NewList ScriptLine.s()
CmdLine$ = ProgramParameter(0)
Path$ = GetPathPart(CmdLine$)
Name$ = GetFilePart(CmdLine$)
If FileSize(CmdLine$) > 1
ReadFile(6, CmdLine$)
While Eof(6) = 0
AddElement(ScriptLine())
ScriptLine() = ReadString(6)
Debug ScriptLine()
Wend
CloseFile(6)
EndIf
; K = CountString(Script$, #LF$)
; For X = 1 To K+1
; AddElement(ScriptLine())
; ScriptLine() = StringField(Script$, X, #LF$)
; Next
Dim Fields.s(10)
For X = 0 To ListSize(ScriptLine())-1
SelectElement(ScriptLine(), X)
Debug ScriptLine()
If Trim(ScriptLine()) = ""
Continue
EndIf
Line$=Trim(ScriptLine())
Debug Line$
Cmd$ = StringField(Line$, 1, "(")
Vars$ = StringField(Line$, 2, "(")
If Cmd$="Delay"
Vars$ = ReplaceString(Vars$, "(","")
Vars$ = ReplaceString(Vars$, ")","")
Delay(Val(Vars$))
Else
ParseParams(Vars$, Fields())
If Cmd$ = "AUTOIT::Run"
; "C:\Windows\System32\notepad.exe", "C:\Windows\System32\", 1
AUTOIT::Run(Fields(1), Fields(2), Val(Fields(3)))
EndIf
EndIf
Next
FreeArray(Fields())
FreeList(ScriptLine())
EndIf
EndProcedure