Skip to content

system.util.runPython #50

@JosephTLockwood

Description

@JosephTLockwood

Allows users to run complete Python scripts directly from Ignition.

This would allow users to install any Python library on a local computer and pass data.

from java.lang import ProcessBuilder, String
from java.io import File
	
# Function to run a Python script using the specified file path and arguments
def runPython(python_script_path, python_executable= r'C:\Python\Python311\python.exe', *args):
    # Construct the command to execute the Python script
    command = [python_executable, python_script_path] + list(args)
    # Create a ProcessBuilder with the command
    pb = ProcessBuilder(command)  
    # Start the process
    process = pb.start()
    # Read the output from the process
    output = process.getInputStream().readAllBytes()
    # Return the output
    return output

I will work on this in my free time; however, I wanted to post it for documentation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions