Launching a script - SOLVED!

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

mightycpa
Automation Wizard
Posts: 343
Joined: Mon Jan 12, 2004 4:07 pm
Location: Vienna, VA

Re: Launching a script - SOLVED

Post by mightycpa » Fri Mar 19, 2021 1:46 am

This ended up being too easy! Thanks to everyone who lent a hand.

The solution. This:

Code: Select all

Run>%COMMAND_LINE% "%v_scp_next_3%"
changes to this:

Code: Select all

ExecuteFile>%v_scp_next_3%
Doing this has the added benefit of making the launch script completely unnecessary. The Exit> command that follows this line also shuts down the calling script, and removes it from memory. Exactly what I wanted!

Having solved that, I decided to get fancy. As a developer or tester, depending on the situation, I might want to
  • quit the script
  • work on the script or test it, by running the same script over and over, again and again
  • traverse once through all the scripts, in order
  • loop through all the scripts in order, over and over
So I changed the MyExit code block:

Code: Select all

Label>MyExit
Include>%SCRIPT_DIR%\load_prog_ini.scp
GoSub>NEXT_ONE
Let>RP_WAIT=0

If>%v_debug%=Y
  Ask>%SCRIPT_NAME% IS DONE. Do you want to run the next one?,v_continue
  If>%v_continue%=YES
      Ask>Examine variables?,v_examine
      If>v_examine=YES
//this is here on purpose, in case you want to look at variable values
**BREAKPOINT**
      Endif  // v_examine
      //Dev and Test
      MessageModal>%SCRIPT_DIR%\%SCRIPT_NAME% will run %v_next_scp%
      ExecuteFile>%v_next_scp%
      Wait>2
      Exit>
  Else
      MessageModal>%SCRIPT_DIR%\%SCRIPT_NAME% will now end
      Exit>
  Endif  // v_continue
Else
    //Production
    Run>%SCRIPT_DIR%\%v_next_prog%
    Exit>
Endif
Exit>
and added some logic to the load_prog_ini script:

Code: Select all

//scripts
//SCRIPTS LOOP, TRAVERSE, REPEAT OR END
//LOOP RUNS EACH SCRIPT IN ORDER, AND LOOPS FOREVER
//TRAVERSE RUNS EACH SCRIPT ONCE IN ORDER
//REPEAT RUNS EXECUTING SCRIPT AGAIN
//END STOPS THE EXECUTING SCRIPT
// one for scripts, one for compiled
Let>v_scp_repeat=TRAVERSE
Let>v_exe_repeat=TRAVERSE


ArrayDim>v_script,3
Let>v_script_1=%SCRIPT_DIR%\start.scp
Let>v_script_2=%SCRIPT_DIR%\middle.scp
Let>v_script_3=%SCRIPT_DIR%\end.scp
Let>v_scp_first=%v_s%

//compiled script names
ArrayCount>v_script,v_ra_cnt
ArrayDim>v_prog,%v_ra_cnt%
Let>v_kay=0
Repeat>v_kay
  Let>v_kay=v_kay+1
  StringReplace>v_script_%v_kay%,scp,exe,v_prog_name
  Let>v_prog_%v_kay%=v_prog_name
  Endif
Until>v_kay=%v_ra_cnt%

//Calculates the next script possible
SRT>NEXT_ONE
ArrayCount>v_script,v_ra_cnt
Let>v_this_script=%SCRIPT_DIR%\%SCRIPT_NAME%.scp
Let>v_kay=0
Repeat>v_kay
  Let>v_kay=v_kay+1
  Let>v_compare=v_script_%v_kay%
  If>%v_compare%=%v_this_script%
    Let>v_jay=v_kay+1
    Let>v_kay=%v_ra_cnt%
    Let>v_next_scp=v_script_%v_jay%
    StringReplace>v_next_scp,scp,exe,v_next_exe
  Endif
Until>v_kay=%v_ra_cnt%

//Determines the next script
// by applying rules

//MessageModal>Next item is %v_next_scp%
Assigned>v_next_scp,v_var_assigned
//in case there are more array vars than scripts

Position>v_script_,%v_next_scp%,1,v_string_pos
If>%v_string_pos%>0
  Let>v_var_assigned=FALSE
Endif

//Assigned or not, these are first rules
If>v_scp_repeat=REPEAT
  Let>v_next_scp=%SCRIPT_DIR%\%SCRIPT_NAME%.scp
Endif
If>v_exe_repeat=REPEAT
  Let>v_next_prog=%SCRIPT_DIR%\%SCRIPT_NAME%.exe
Endif

If>v_scp_repeat=END
  Let>v_next_scp=%SCRIPT_DIR%\exit.scp
Endif
If>v_exe_repeat=END
  Let>v_next_prog=%SCRIPT_DIR%\exit.exe
Endif

//If still not assigned
If>v_var_assigned=FALSE

  If>v_scp_repeat=TRAVERSE
    Let>v_next_scp=%SCRIPT_DIR%\exit.scp
  Endif
  If>v_exe_repeat=END
    Let>v_next_prog=%SCRIPT_DIR%\exit.exe
  Endif


  //scp
  If>v_scp_repeat=LOOP
    Let>v_next_scp=%v_script_1%
  Else
    Let>v_next_scp=%SCRIPT_DIR%\exit.scp
  Endif
  //exe
  If>v_exe_repeat=LOOP
    Let>v_next_prog=%v_prog_1%
  Else
    Let>v_next_prog=%SCRIPT_DIR%\exit.scp
  Endif
Endif


END>NEXT_ONE
It runs like a charm. It needs to be tested more thoroughly, but this code is now destined to be part of my default template.

The only thing left is to pass the debug variable on the command line instead of hardcoding it.
"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey

mightycpa
Automation Wizard
Posts: 343
Joined: Mon Jan 12, 2004 4:07 pm
Location: Vienna, VA

Re: Launching a script - SOLVED!

Post by mightycpa » Fri Mar 19, 2021 9:29 pm

After a little more thorough testing:

template.scp

Code: Select all

//put the files wherever you want

//Include> your code between these two lines, just be sure to exit to "MyExit"


//Include> your code between these two lines

Label>MyExit
Include>%SCRIPT_DIR%\load_prog_ini.scp
GoSub>NEXT_ONE
Let>RP_WAIT=0
//scripts can have Y or N, exe is always N.

ProcessExists>%SCRIPT_NAME%.exe,v_compiled
If>v_compiled=False
  //DEV and TEST
  If>%v_debug%=Y
    Ask>%SCRIPT_NAME% IS DONE. Do you want to run the next one?,v_continue
    If>%v_continue%=YES
        Ask>Examine variables?,v_examine
        If>v_examine=YES
  //this is here on purpose, in case you want to look at variable values
**BREAKPOINT**
        Endif  // v_examine
        MessageModal>%SCRIPT_DIR%\%SCRIPT_NAME% will run %v_next_scp%
        ExecuteFile>%v_next_scp%
        Wait>2
        Exit>
    Else
        MessageModal>%SCRIPT_DIR%\%SCRIPT_NAME% will now end
        Exit>
    Endif  // v_continue
  Else
    ExecuteFile>%v_next_scp%
    Wait>2
    Exit>
  Endif  // v_debug
Else
  //Production
  Let>v_debug=N
  RunProgram>%v_next_exe%
  Exit>
Endif
Exit>

exit.scp

Code: Select all

// COMPILE_OPTS|C:\MS15\TEST_1\exit.exe||CONSOLE=0|INCLUDES=1||RUNTIMES=1|BMPS=1
//Set IGNORESPACES to 1 to force script interpreter to ignore spaces.
//If using IGNORESPACES quote strings in {" ... "}
//Let>IGNORESPACES=1

DeleteFile>%SCRIPT_DIR%\debug.ini
Wait>2
Exit>
load_prog_ini.scp

Code: Select all

//check for v_debug, if unavailable
//check ini file, if that's unavailable
//then create ini file, set to Y
//the exit script will delete it
Assigned>v_debug,v_default
Let>v_there=0
If>v_default=False
//not assigned, get it from ini file
  IfFileExists>%SCRIPT_DIR%\debug.ini
    ReadIniFile>%SCRIPT_DIR%\debug.ini,DEBUG,debug,v_debug
    //determine if it exists or not, if not, create it
    Len>%v_debug%,v_one
    If>v_one>0
      Let>IGNOREERRORS=1
      Position>%v_debug%,YN,1,v_there
    Else
      Let>v_there=0
    Endif
    //if not,default to Y and write it to ini file
    If>%v_there%=0
      Let>v_debug=Y
      EditIniFile>%SCRIPT_DIR%\debug.ini,DEBUG,v_debug,%v_debug%
    Endif
  Else
  //ini file doesn't exist so create one
    Let>v_debug=Y
    WriteLn>%SCRIPT_DIR%\debug.ini,v_rezult,[DEBUG]
    WriteLn>%SCRIPT_DIR%\debug.ini,v_rezult,v_debug=Y
  Endif
Else
//value is assigned, ensure correct value is place in ini file
  IfFileExists>%SCRIPT_DIR%\debug.ini
    EditIniFile>%SCRIPT_DIR%\debug.ini,DEBUG,v_debug,%v_debug%
  Else
  //ini file doesn't exist so create one
    Let>v_debug=Y
    WriteLn>%SCRIPT_DIR%\debug.ini,v_rezult,[DEBUG]
    WriteLn>%SCRIPT_DIR%\debug.ini,v_rezult,v_debug=%v_debug%
  Endif
Endif
//exit.scp deletes the ini file


//scripts

//SCRIPTS LOOP, TRAVERSE, REPEAT OR END
//LOOP RUNS EACH SCRIPT IN ORDER, AND LOOPS FOREVER
//TRAVERSE RUNS EACH SCRIPT ONCE IN ORDER
//REPEAT RUNS EXECUTING SCRIPT AGAIN
//END STOPS THE EXECUTING SCRIPT
// one for scripts, one for compiled
Let>v_scp_repeat=TRAVERSE
Let>v_exe_repeat=TRAVERSE


ArrayDim>v_script,3
Let>v_script_1=%SCRIPT_DIR%\start.scp
Let>v_script_2=%SCRIPT_DIR%\middle.scp
Let>v_script_3=%SCRIPT_DIR%\end.scp
Let>v_scp_first=%v_script_1%

//compiled script names
ArrayCount>v_script,v_ra_cnt
ArrayDim>v_prog,%v_ra_cnt%
Let>v_kay=0
Repeat>v_kay
  Let>v_kay=v_kay+1
  StringReplace>v_script_%v_kay%,scp,exe,v_prog_name
  Let>v_prog_%v_kay%=v_prog_name
  Endif
Until>v_kay=%v_ra_cnt%

//Calculates the next script possible
SRT>NEXT_ONE
ArrayCount>v_script,v_ra_cnt
Let>v_this_script=%SCRIPT_DIR%\%SCRIPT_NAME%.scp
Let>v_kay=0
Repeat>v_kay
  Let>v_kay=v_kay+1
  Let>v_compare=v_script_%v_kay%
  If>%v_compare%=%v_this_script%
    Let>v_jay=v_kay+1
    Let>v_kay=%v_ra_cnt%
    Let>v_next_scp=v_script_%v_jay%
    StringReplace>v_next_scp,scp,exe,v_next_exe
  Endif
Until>v_kay=%v_ra_cnt%

//Determines the next script
// by applying rules

//MessageModal>Next item is %v_next_scp%
Assigned>v_next_scp,v_var_assigned
//in case there are more array vars than scripts
Position>v_script_,%v_next_scp%,1,v_string_pos

//MessageModal>position found: %v_string_pos%
If>%v_string_pos%>0
  Let>v_var_assigned=False
Endif

//Assigned or not, these are first rules
If>v_scp_repeat=REPEAT
  Let>v_next_scp=%SCRIPT_DIR%\%SCRIPT_NAME%.scp
Endif
If>v_exe_repeat=REPEAT
  Let>v_next_prog=%SCRIPT_DIR%\%SCRIPT_NAME%.exe
Endif

If>v_scp_repeat=END
  Let>v_next_scp=%SCRIPT_DIR%\exit.scp
Endif
If>v_exe_repeat=END
  Let>v_next_prog=%SCRIPT_DIR%\exit.exe
Endif

//If still not assigned
If>v_var_assigned=False

  If>v_scp_repeat=TRAVERSE
    Let>v_next_scp=%SCRIPT_DIR%\exit.scp
  Endif
  If>v_exe_repeat=TRAVERSE
    Let>v_next_prog=%SCRIPT_DIR%\exit.exe
  Endif


  //scp
  If>v_scp_repeat=LOOP
    Let>v_next_scp=%v_script_1%
  Else
    Let>v_next_scp=%SCRIPT_DIR%\exit.scp
  Endif
  //exe
  If>v_exe_repeat=LOOP
    Let>v_next_exe=%v_prog_1%
  Else
    Let>v_next_exe=%SCRIPT_DIR%\exit.exe
  Endif
Endif




END>NEXT_ONE
"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts