The NetPhantom Server has been extended with 4 new REXX and NetRexx functions that runs on the
server side:
- CreateTempFile,
- RemoveTempFile,
- DeleteFile,
- ExecuteProcess.
CreateTempFile
The CreateTempFile function has no parameters and creates a temporary file with the name nnnnnnnn.tmp
in the directory of the current runtime file. When the client disconnects from the server, all its
temporary files are deleted (unless the server is aborted, e.g. by Ctrl+C or "terminate process"). Temporary
files can be deleted at an earlier stage by usage of the RemoveTempFile function.
CreateTempFile returns a fully qualified file name (includes drive [not for e.g. Unix] and directory specification). If
CreateTempFile fails, e.g. because the client session is disconnected, an empty string is returned.
RemoveTempFile
The RemoveTempFile function has a file name returned from CreateTempFile function as the only parameter.
It will delete the file from disk and remove the file from the deletion list when the client disconnects.
RemoveTempFile returns "0" (zero) if successful operation and "1" for failure.
DeleteFile
The DeleteFile function has a file name as the only parameter. It will delete the file from disk,
but does not remove the file from the deletion list when the client disconnects.
DeleteFile returns "0" (zero) if successful operation and "1" for failure.
ExecuteProcess
This function executes a process, waiting for the response code and reads the STDOUT/STDERR output streams.
The process will execute in the directory specified (only works with JDK 1.3 or better).
The environment variables will be set from the currently set NetPhantom Global Variables.
The cmdLine parameter will be parsed (as under Windows) with quotes when executing the process
under Unix-like operating systems.
Syntax:
reply = ExecuteProcess(currentDirectory, useRuntimeDirectory, cmdLine)
- currentDirectory
The currentDirectory indicates the current directory of the process (only available when the NetPhantom
Server runs using JDK 1.3 or better). Leave this parameter empty to use the server root directory or if
the server runs using Microsoft JVM or JDK 1.1 to 1.2.
- useRuntimeDirectory
The parameter useRuntimeDirectory can be "0" (zero) for no special directory (if currentDirectory
is empty) or "1" (one) to set the process current directory to the directory of the current runtime file.
Leave this parameter to "0" (zero) to use the server root directory if the server runs using Microsoft JVM or
JDK 1.1 to 1.2.
- cmdLine
The parameter cmdLine is the process to run including optional arguments. Enclose arguments within
quotes if they contain spaces (e.g. long file names).
- reply
The reply return string is empty string for failure when a directory is specified and/or the JDK is not 1.3
or better, otherwise a return string indicating the return code of the process concatenated with '\x01',
STDOUT stream as a string, '\x01', followed with STDERR stream as string. A negative return code from the
process indicates an error, in which case STDERR contains the error message.
Note: all processes running for a client session are destroyed when the client is disconnected from the server.
Examples:
- Executing the MyBatchFile.bat command file under Windows 2000 or better using JDK 1.3 or better
(because the current directory "C:\MyDir" is specified):
reply = ExecuteProcess('C:\MyDir', 0, 'cmd.exe /c C:\TEMP\MyBatchFile.bat')
- Executing the C:\TEMP\MyBatchFile.bat command file under Windows 2000 or better using JDK 1.3 or better
(because the directory of the current runtime file is specified):
reply = ExecuteProcess('not-used', 1, 'cmd.exe /c C:\TEMP\MyBatchFile.bat')
- Executing the C:\TEMP\MyBatchFile.bat command file under Windows 2000 using the server root
directory as the current directory:
reply = ExecuteProcess('not-used', 0, 'cmd.exe /c C:\TEMP\MyBatchFile.bat')
- Parsing the reply string:
Parse Var reply rc '01'X stdout '01'X stderr
resulting in rc containing the return code of the process, stdout the output of the process "Standard output" stream
and stderr the output of the process "Standard error" stream.