ex37.pp 914 B

1234567891011121314151617181920212223242526272829303132333435
  1. Program Example37;
  2. { Program to demonstrate the Popen function. }
  3. uses linux;
  4. var f : text;
  5. i : longint;
  6. begin
  7. writeln ('Creating a shell script to which echoes its arguments');
  8. writeln ('and input back to stdout');
  9. assign (f,'test21a');
  10. rewrite (f);
  11. writeln (f,'#!/bin/sh');
  12. writeln (f,'echo this is the child speaking.... ');
  13. writeln (f,'echo got arguments \*"$*"\*');
  14. writeln (f,'cat');
  15. writeln (f,'exit 2');
  16. writeln (f);
  17. close (f);
  18. chmod ('test21a',octal (755));
  19. popen (f,'./test21a arg1 arg2','W');
  20. if linuxerror<>0 then
  21. writeln ('error from POpen : Linuxerror : ', Linuxerror);
  22. for i:=1 to 10 do
  23. writeln (f,'This is written to the pipe, and should appear on stdout.');
  24. Flush(f);
  25. Writeln ('The script exited with status : ',PClose (f));
  26. writeln;
  27. writeln ('Press <return> to remove shell script.');
  28. readln;
  29. assign (f,'test21a');
  30. erase (f)
  31. end.