Execution Of Linux Commands

Execution of Linux commands is possible this way:

PROCEDURE Do*;
VAR pid, res: LONGINT; argv, envp: ARRAY 12 OF LONGINT;
BEGIN
    argv[0]:=SYSTEM.ADR("/bin/ls");
    argv[1]:=SYSTEM.ADR("/.");
    argv[2]:=SYSTEM.ADR("-l");
    argv[3]:=0;
    envp[0]:=0;
    pid:=Linux0.Fork0();
    IF pid=0 THEN res:=Linux0.Execve0(argv[0], SYSTEM.ADR(argv[0]), SYSTEM.ADR(envp)); 
    ELSIF pid<0 THEN  Out.String("error"); Out.Int(pid, 6); Out.Ln;
    END;
END Do;

For every argument, copy the address to argv[n]. envp only tested when empty. This way, the parent process does not wait for the finishing of the child process. Be aware, no pre-processing takes place. Commands need absolute path names, output re-routing would have to be don in child process, directory "/" does not exist on the filesystem, but "/." does and so on.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License