extProgramStart (Function)

Top  Previous  Next

Architecture:

NX32L

Device support:

All

Firmware version:

1.00.00


This function starts an external program.

The extension program must be installed by adding it to the Platform Extension in the project view, and transferring the project.

 

The program will start with the working directory set to the root of the internal drive.

 

Input:

path : STRING

The full path to the program to execute, as shown in the Platform Extension dialog.

 

args : STRING

A string with the arguments to the program.

The arguments are separated by spaces, use double quotes(") to include a space in an argument.

Currently a maximum of 9 parameters are supported.

 

Output:

handle : SYSHANDLE

A handle to the started program.

 

Returns: INT

0

- The program was started. The handle parameter now contains a handle to the program.

-1

- A handle could not be created. Too many program handles may have been created. Use extProgramStatus to release exited programs.

-2

- Invalid path. Make sure that the path is correct and that the drive is open.

-3

- Could not start program.

-4

- Invalid program.

-6

- Program was build for a different architecture.

 

Declaration:

FUNCTION extProgramStart : INT;
VAR_INPUT
  path : STRING;
  args : STRING;
  handle : ACCESS SYSHANDLE;
END_VAR;

 

 

Example:

INCLUDE rtcu.inc
 
PROGRAM test;
VAR
  rc     : INT;
  signal : DINT;
  handle : SYSHANDLE;
END_VAR;
 
BEGIN
  ...
  fsMediaOpen(media := 1);
  // Start the program SERVER.RPX with four arguments: "-port" "3490" "-name" and "test server".
  rc := extProgramStart(handle := handle, path := "B:\SYSTEM\EXT\SERVER.RPX",
     args := "-port 3490 -name $"test server$"");
  DebugFmt(message := "Server started: \1", v1 := rc);
  ...
  // Stop the program by sending the Terminate signal
  rc := extProgramSignal(handle := handle, signal := 9);
  DebugFmt(message := "Send kill: \1", v1 := rc);
  // Request status
  rc := extProgramStatus(handle := handle, code := signal);
  IF rc = 2 THEN
    DebugFmt(message := "Program was terminated with the \4 signal", v4 := signal);
  END_IF;
END;
END_PROGRAM;