Overview | Statement List | Example


执行操作系统功能

Synopsis

There are two formats to this statement:

Format 1

XSPAWN/[CONCUR,][PROG,]'program name'[,'argument list1',.., 'argument listn'][,RESULT,result string variable][,IFERR,label:]

Format 2

XSPAWN/UFUN,'program name'[,IFERR,label:]

Description

This statement allows user functions, system commands, and user programs to be executed from a GRIP program. It allows user to pass up to 30 input arguments to the child processes.

NOTE: On the UNIX Operating System, operating system commands cannot be used as arguments to the XSPAWN statement; instead, the path must be fully specified (/bin/cp). For more details, refer to Subroutine for XSPAWN.

Parameters

Parameter

Description

CONCUR

Minor word which indicates that the specified program or system command is to be executed concurrently with the GRIP program. If CONCUR is included, the GRIP program will not wait for that program or system command to finish executing before continuing with the next GRIP statement.

NOTE: Any attempt to run an interactive program concurrently with Unigraphics will fail. Unigraphics cannot share its terminal with another process.

PROG

Minor word which indicates that the program name is that of an executable module such as a C program. If PROG is not included, the program name is assumed to be a system command.

NOTE: For more information on program communications with the XSPAWN command, refer to the respective SYSOP manual. The subroutines used to convert data to and from the operating system format are listed Subroutine for XSPAWN.

UFUN

Minor word which indicates that a user function program is being run. The program name can specify either an external or internal user function program.

'program name'

A string or string variable which represents the name of the program to be executed. The program name must be fully specified including the directory and file extension. The standard character limitations apply to pathnames (256 characters) and filenames (132 characters including the period and file extension).

'argument list1',..'argument listn'

Pass up to 30 input argument lists to the child processes. Each argument list is separated by a comma. Each argument list is a string or string variable which consists of the values to be passed to the program, command list or utility being executed. Each string length may be up to 132 characters long and the values must be separated by a space or a comma.

NOTE: The XSPAWN command is allowed in GRIP Batch but there are strict limitations. Terminal I/O is not allowed under any circumstance, and some system commands return confirmation messages to the terminal that cannot be dealt with by the batch process.

The batch process may also be running in a different directory than the interactive process; therefore, the user should be careful to include the full path name in any file or program specifications.

RESULT

Minor word which indicates that a returned value is expected. Result string variable is only valid with the PROG option. In addition, results can not be returned to GRIP while running concurrent executions.

result string variable

A string variable which receives the returned value from the program, command list, or utility being executed. The length of the string variable may be up to 132 characters long.

IFERR,label:

Specifies a label to which the program jumps if an error occurs.

User Function Programs

XSPAWN/UFUN,'program pathname'

Example

XSPAWN/UFUN,'/users/ugii/ufuser'

Executing User Written Programs

XSPAWN/[CONCUR],PROG,'program pathname'
[,'arguments',..,'arguments'][,RESULT,string]

This form of the XSPAWN command can be used to start up a user written or user specified program. If concurrent execution is specified, then results can not be returned to the GRIP program. If nonconcurrent execution is specified, then Unigraphics waits for the subprocess to terminate. External user function programs can be executed using this method.

Subroutines for XSPAWN

This section covers the subroutines used with the PROG switch on the GRIP XSPAWN statement. These subroutines are used to transmit data to and from the operating system while they execute. These subroutines are machine dependent, and will be covered by operating system.

UNIX

The GRIP XSPAWN statement allows access to user-written C programs. It is possible to run scripts and programs, including internal and external user function programs. Scripts and standard programs can be run concurrently and you can optionally pass information between your application and GRIP. The XSPAWN facility is implemented on UNIX using fork(2) and exec(2).

If you are using the PROG switch, the transmitting and receiving of the data to and from this program may be accomplished by using the User Function routine UC4622.

UC4622

This routine is used by the "C" programs to pass back the result string. C Programs can retrieve arguments passed by XSPAWN from the AFGC and ARGV variables to the main routine.

File Access

In general, it is always advisable to use full pathnames whenever possible. In GRIP Batch, problems can occur if the GRIP Batch process has a different default directory than the interactive user. Problems can also occur if the files accessed are protected, as GRIP Batch can be running under a different user account.

GRIP Batch also has no way to deal with terminal I/O. If a GRIP program is being run from GRIP Batch, any program or script being called using XSPAWN should be designed with the idea that standard input and standard output are not available.

XSPAWN Options

Executing Scripts

The following form of the XSPAWN command can be used to start up a script:

XSPAWN/[CONCUR,]'script pathname'[,'arguments']

The script is run by either /bin/sh, /bin/csh, or /bin/ksh, depending on how the environment variable SHELL is set. Arguments can be passed to the script by XSPAWN, but the script can not return any results to GRIP. If the CONCUR option is specified then Unigraphics immediately returns once the script is started.

The following example starts the script /users/ugii/sample:

XSPAWN/'/users/ugii/sample','test1',' test2'

Argument one is test1, and argument two is test2. While the script is executing, Unigraphics is blocked.

The next example starts the script /users/ugii/backup.

XSPAWN/CONCUR,'/users/ugii/backup','/users/ugii/parts'

Argument one is /users/ugii/parts. Once the script is started, Unigraphics continues without waiting.

Executing Shell Commands

You can execute shell commands with XSPAWN. For example, the redirection ">" of output is handled by the shell. The following code directs the output of the env command to a file:

XSPAWN/ '/bin/ksh' , '-c' , '/bin/env> output_file'

Executing DOS Commands in Windows NT

You can execute DOS commands with XSPAWN. Use the following syntax:

XSPAWN/ 'cmd.exe', '/c', 'DOS command goes here'

Executing User Written Programs

The following form of the XSPAWN command can be used to start up a user written or user specified program:

XSPAWN/[CONCUR,]PROG,'program pathname'
[,'arguments'][,RESULT,string]

If concurrent execution is specified, then results can not be returned to the GRIP program. If nonconcurrent execution is specified then Unigraphics waits for the subprocess to terminate. External User Function programs can be executed using this method.

If arguments are passed to a program they are passed on the command line. The program can pick up the arguments by reading the command line. Once the user written program finishes, results can be passed back to the GRIP program by calling the UC4622 subroutine, also supplied with Unigraphics. UC4622 is the only way a user written program can communicate results back to Unigraphics. UC4622 is only available if the PROG switch is set and the CONCUR option is not used.


Copyright ©2015 胡君NX二次开发官网(www.UGapi.com) QQ:85585969 All Rights Reserved.