mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-13 08:19:25 +02:00
33 lines
833 B
ObjectPascal
33 lines
833 B
ObjectPascal
Program Example37;
|
|
|
|
{ Program to demonstrate the Popen function. }
|
|
|
|
uses linux;
|
|
|
|
var f : text;
|
|
i : longint;
|
|
|
|
begin
|
|
writeln ('Creating a shell script to which echoes its arguments');
|
|
writeln ('and input back to stdout');
|
|
assign (f,'test21a');
|
|
rewrite (f);
|
|
writeln (f,'#!/bin/sh');
|
|
writeln (f,'echo this is the child speaking.... ');
|
|
writeln (f,'echo got arguments \*"$*"\*');
|
|
writeln (f,'cat');
|
|
writeln (f);
|
|
close (f);
|
|
chmod ('test21a',octal (755));
|
|
popen (f,'./test21a arg1 arg2','W');
|
|
if linuxerror<>0 then
|
|
writeln ('error from POpen : Linuxerror : ', Linuxerror);
|
|
for i:=1 to 10 do
|
|
writeln (f,'This is written to the pipe, and should appear on stdout.');
|
|
closep (f);
|
|
writeln;
|
|
writeln ('Press <return> to remove shell script.');
|
|
readln;
|
|
assign (f,'test21a');
|
|
erase (f)
|
|
end. |