[fpc-pascal]popen problems...
Martyn Ranyard
ranyardm at lineone.net
Wed Aug 14 15:35:12 CEST 2002
Hi all,
I am writing a menu program in FPC, gpl'd so I'm asking here for
comments, as I don't quite understand why my calls are no longer working.
I used this call in a completely different menu program, and it worked
nicely. Can't remember if it was a different version of FPC, but I'm now
running on "Free Pascal Compiler version 1.0.6 [2002/04/30] for i386". I
just don't quite get it. I did write this heap of ****, but it was quite a
while ago, and it was by trial and error - I even ended up with zombies in
an early revision because I used close() instead of pclose(). :(
The call :
ExecAndDisplay('/home/mranyard/newmenuserv/usr/sbin/smeserver/share2iso.sh
/usr/share/ToBurn /tmp/duplicate.iso ASK');
or the call :
ExecAndDisplay('/bin/sh -c
''/home/mranyard/newmenuserv/usr/sbin/smeserver/share2iso.sh
/usr/share/ToBurn /tmp/duplicate.iso ASK''');
gives :
An unhandled exception occurred at 0x08069D5F :
Unknown Run-Time error : 029
0x08069D5F
0x08074E0F
0x080480B0
and yes, the file share2iso.sh exists and has execute rights - It executes
if I copy the command out into the command prompt.
and now for the heap (remember - early code, please don't be too nasty,
also, I know it does no more than shell() would do, but there is a similar
function yet to be made that will do more with the output.) :
Procedure ExecAndDisplay(Command: String);
Var
TheFile : File;
Ch : Char;
TheBuff : String;
EndOfFile : Boolean;
Begin
EndOfFile := False;
popen(TheFile, Command, 'r');
Repeat
If not Eof(TheFile) then
Begin
If not Eof(TheFile) then
Begin
TheBuff := '';
Repeat
If Eof(TheFile) then
Ch := #10
else
Try
BlockRead(Thefile, Ch, 1)
Except
EndOfFile := True;
Ch := #10
End;
If Ch = #13 then Ch := #10;
if Ch <> #10 then TheBuff := TheBuff + Ch
Until Ch = #10;
Writeln(TheBuff);
End
End
Until Eof(TheFile) or EndOfFile;
pClose(TheFile)
End;
Martyn Ranyard
Free Software Advocate
jabber - joran at amessage.de
icq - 122500800
irc - Joran on oftc
msn - ranyardm at hotmail.com
e - ranyardm at lineone.net
More information about the fpc-pascal
mailing list