Geoffrey Arnold wrote:
I have GPC version 2.0 compiled for a 486 running linux.
How do I execute a external shell script from a pascal program?
You can use the system(3) function from libc. The first program passes a Pascal string to a CString parameter which is only supported by very recent (alpha) GPC versions. The second program does the conversion explicitly, and therefore works with older GPC versions as well. I'm not sure if it works with 2.0 since I don't have that here for testing. Anyway, it might be a good idea to get a newer version, which, though alpha, is already more stable than 2.0 was.
program Exec_Demo;
function System (cmd: CString): Integer; C;
var s: String (1000); i: Integer;
begin Write ('Enter a system command: '); Readln (s); i := System (s); Writeln ('The returned status of the executed command was ', i, '.') end.
program Exec_Demo;
function System (cmd: CString): Integer; C;
function Str2CStrRO (var s: String): CString; begin s[Length(s)+1] := #0; Str2CStrRo := @s[1] end;
var s: String (1000); i: Integer;
begin Write ('Enter a system command: '); Readln (s); i := System (Str2CStrRO (s)); Writeln ('The returned status of the executed command was ', i, '.') end.
Frank