Language

Operating system operations

Executing an external program

This is achieved through Pliant 'execute' instruction:

module "/pliant/admin/execute.pli"
var Int err := execute "ls -l /tmp/"

The standard for Unix programs is to return zero if everything when fine, nonzero elsewhere.

Under Linux, 'execute' instruction accepts many options:

execute "make bzImage" root "file:/logical/test/" path "file:/logical/test/usr/src/linux/"

'root' option enables to set Unix chrooting jailing,
'path' enables to set the Unix current working directory.

execute "rm /tmp/foo" user 1001 group 2000

'user' enables to set the Unix user ID,
'group' enables to set the Unux group ID.

execute "telnet" input "file:/tmp/input.txt" output "file:/tmp/output.txt" error "file:/tmp/error.txt"

'input' enables to redirect the Unix standard input (file handle 0),
'output' enables to redirect the Unix standard output (file handle 1),
'error' enables to redirect the Unix error file (file handle 2).

execute "make bzImage" output "file:/tmp/output.txt" mixed

The Unix error file will be the same as the output file.

execute "make bzImage" output "file:/tmp/output.txt" quiet

The Unix error file will be discarded.

execute "make bzImage" quiet

The Unix output and error files will be discarded since no 'ouput' option has been provided.

var Str env := ""
env += "PATH=/bin[0]"
env += "QEMU_AUDIO_DRV=oss[0]"
execute "kvm" environment env

Enables to set the Unix environment provided to the program. Please notice that all variables are provided in a single Pliant string, and that each environment variable setting, including the last one, is followed by a character zero.

execute "make bzImage" detached id (var Str pid)

'detached' option specifies that the program will be executed asynchronously from the current thread, so execution if the current thread will resume immediately. In such a situation, the fact that execute function returns zero does not mean that the executed program ended fine, but only that the program started fine.
If 'id' option is furthermore provided, the Unix process ID of the program will be stored in the provided variable.