Option: --runscript (run script) Permalink

The specified script file is run by CODESYS.

Table 547: Command Line Options for --runscript

‎--runscript="<script file>.py"‎

CODESYS runs the ‎<script file>.py‎ script file at startup.

You have to provide the complete path of the script file.

‎--scriptargs:'<arg1> <arg2> ... <argn>'‎

Use this option with the ‎--runscript‎ option. They trigger the passing of the <arg1> … <argn> arguments to the script. The arguments are passed to the Python variable ‎sys.argv‎.

‎--noUI‎

Use this option with the ‎--runscript‎ option.

The CODESYS user interface is not opened. CODESYS outputs all errors, warnings, compiler reports, and command-line messages generated from the script. The script messages (1: Severity Text) can be separated from other messages (2: Severity FatalError, Error, Warning, Information) with the ‎>‎ operator.

‎--enablescripttracing‎

Use this option with the ‎--runscript‎ option. As a result, each command of the script file is shown in the output.

‎--textPrompts‎

Use this option with the ‎--noUI‎ option. As a result, message service methods and default dialogs are output in the command line for user input.

If you do not specify ‎--textPrompts‎, then all message service prompts are confirmed automatically with default values.

Examples of using transfer parameters in script files with 'sys.argv'

start /b /wait Automation Builder.exe 
--runscript="D:\Script\ArgvAnd__main__Test.py" 
--scriptargs:'username password 3.14 "path=\"C:\temp\\"' 

Script file: ‎ArgvAnd__main__Test.py‎

from __future__ import print_function
import sys
print("sys.argv: ", len(sys.argv), " elements:")

for arg in sys.argv:
    print(" - ", arg)
print()
print("__name__: ", __name__)

Output result: ‎stdout‎:

sys.argv: 6 elements:
- D:\TestScripts\ArgvAnd__main__Test.py
- username
- password
- 3.14
- path= "C:temp"
__name__: __main__

For more information about the ‎__name__‎ global variable, see the Python documentation.

Examples of the message output

start /b /wait Automation Builder.exe --runscript="D:\Script\AmpelTest.py" --noUI 1>ScriptMessages.txt

CODESYS passes all messages which are generated by the script to the ‎ScriptMessages.txt‎ file. Other messages are printed to the command line.

start /b /wait Automation Builder.exe --runscript="D:\Script\AmpelTest.py" --noUI 2>NUL

CODESYS suppresses all messages, except for script messages. The script messages are printed to the command line.

Example of using the –scriptdebugger option

The following ‎initdebug.py‎ script was tested successfully with ‎pydevd‎-based debuggers, such as PyDev / LiClipse and PyCharm. To use this script, start CODESYS with the following command line:

--profile="Fanta Development Build" --scriptdebugger="D:\test\charmdebug\initdebug.py"

File: ‎initdebug.py‎:

from _future_ import print_function
from _future_ import unicode_literals
import sys
sys.path.append(r"D:\test\Env2\Lib\site-packages\pycharm-debug.egg")
import pydevd
def scriptdebuggersetup():
pydevd.settrace('localhost', port=51234, stdoutToServer=True, stderrToServer=True)
def scriptdebuggershutdown():
pydevd.stoptrace()

For more information, see: and ‎⮫ http://docs.python.org/tutorial/modules.html