(cedar-imports "UnixSpawn" "PFS" "UnixSysCalls" "SchemeSys") (cedar-directory "Rope" "UnixTypes") (cedar-require "Require Cedar UnixCommands UnixSpawn") (release-as "Cedar" "Scheme") ROPE: TYPE ~ Rope.ROPE; (primitive-enable UnixSpawn.Error => { Complain[code, msg]; }; ) devNull: ROPE = "/dev/null"; DeScheme: PROC [ref: REF, inP: BOOL] RETURNS [REF] = { SELECT ref FROM undefined, true => ref _ SchemeSys.GetPort[undefined, inP]; false => ref _ devNull; ENDCASE => { WITH ref SELECT FROM string: Scheme.String => ref _ RopeFromString[string]; ENDCASE => NULL; }; RETURN [ref] }; DeCedar: PROC [a: REF] RETURNS [REF] = { WITH a SELECT FROM lora: LIST OF REF => RETURN [Cons[lora.first, DeCedar[lora.rest]]]; rope: ROPE => RETURN [StringFromRope[rope]]; ENDCASE => RETURN [a]; }; (define-proc (unix-spawn cmd-string (stdin) (stdout) (stderr)) "fork a (Unix) process to run cmd, attaching its standard input, output and error file descriptors to the files named by stdin, stdout, stderr" stdin _ DeScheme[stdin, TRUE]; stdout _ DeScheme[stdout, FALSE]; stderr _ DeScheme[stderr, FALSE]; result _ DeCedar[UnixSpawn.Spawn[command: RopeFromString[TheString[cmdString]], stdin: stdin, stdout: stdout, stderr: stderr, wd: PFS.RopeFromPath[PFS.GetWDir[]], exec: TRUE, tty: FALSE, debug: FALSE].details]; ) (define-proc (unix-getpid) "get unix process id" result _ MakeFixnum[UnixSysCalls.GetPID[]]; ) (define-proc (unix-getppid) "get unix parent process id" result _ MakeFixnum[UnixSysCalls.GetPPID[]]; ) (define-proc (unix-getpgrp pid) "get unix process group" result _ MakeFixnum[UnixSysCalls.GetPGrp[KCheck[pid]]]; ) (define-proc (unix-kill pid signal) "kill (signal) a unix process" res: UnixTypes.SysCallResult = UnixSysCalls.Kill[KCheck[pid], VAL[KCheck[signal]]]; result _ IF res=success THEN true ELSE false; ) (define-proc (unix-killpg pid signal) "kill (signal) a unix process group" res: UnixTypes.SysCallResult = UnixSysCalls.KillPG[KCheck[pid], VAL[KCheck[signal]]]; result _ IF res=success THEN true ELSE false; ) ๊ UnixSysCalls.mx Copyright ำ 1989, 1990, 1991 by Xerox Corporation. All rights reserved. Created by Michael Plass, May 18, 1989 Michael Plass, December 2, 1991 10:01 am PST Last changed by Pavel on April 1, 1990 5:33 pm PDT fork a (Unix) process to run cmd, attaching its standard input, output and error file descriptors to the files named by stdin, stdout, stderr. n.b. the files may be named pipes. The returned value is the exit status of the spawned process or #f for failure. ส+–(cedarcode) style•NewlineDelimiter ™codešœ™Kšœ ฯeœ=™HKšœ&™&Kšœ,™,K™2—Ischeme˜L˜Idefaultšœฯn œ.˜KšœœWœ#™ฑK™OMšœ˜KšœŸœ˜KšœŸœ˜!KšœŸœ˜!Kš œ‚ŸœŸœŸœŸœ Ÿœ ˜าMšœ˜—šœž œ˜Mšœ˜Nšœ+˜+Mšœ˜—šœž œ˜Mšœ˜Nšœ,˜,Mšœ˜—šœž œ˜Mšœ˜Nšœ7˜7Mšœ˜—šœž œ ˜#Mšœ˜Nšœ>Ÿœ˜SNšœ Ÿœ ŸœŸœ˜-Mšœ˜—šœž œ ˜%Mšœ$˜$Nšœ@Ÿœ˜UNšœ Ÿœ ŸœŸœ˜-Mšœ˜—J˜—…—๎