Talk:Executing External Programs
Improved example didn't work for me
I copied the improved example and tried to compile it in lazarus 0.9.7 beta (Date: 22-05-05), using fpc version 2.0.0 [2005/05/16] for i386 - linux, and it gave me this error:
project1.lpr(44,15) Error: identifier idents no member "Lines" project1.lpr(44,35) Error: Illegal expression project1.lpr(44,35) Fatal: Syntax error, ";" expected but "(" found
The line with error is:
AStringList.Lines.ReadFromStream(AProcess.Output);
What's wrong ?
- I fixed the example. Vincent 04:57, 23 May 2005 (PDT)
It compiles now, but when I run it freezes. Running step by step I found that it freezes at the line:
AProcess.Execute;
From a console window, I saw the ppc386 process still running. Then I run 'killall ppc38' and the lazarus program unfroze, and the output.txt file had the right content.
I searched the web a little, and found and alternative way to set WaitOnExit, by changing it this way:
// AProcess.Options := AProcess.Options + [poWaitOnExit, poUsePipes]; AProcess.WaitOnExit;
Now, when I run it raises an error window with the saying:
Project projet1 raised exception class 'External: SIGSEGV'
- If you don't give the option poUsePipes, there are no streams to read from. Vincent 02:16, 25 May 2005 (PDT)
When I click "OK", this windows opens:
Execution Paused Adress: $08064782 Procedure: CLASSES_TSTRINGS_$__LOADFROMSTREAM$TSTREAM File: (Some day an assembler window might popup here:)
I click "OK" again and it shows that the execution stopped at the line:
AStringList.LoadFromStream(AProcess.Output);
Running step by step I confirm that it's this line that raised this excecption. What can I do ?
- I added an example to read more output from the pipe. Tests on my computer indicated a buffer of 64 KB, so unless the output was more then 64 KB, I did not run into trouble. Maybe the pipe buffer on your computer is smaller, so the deadlock occurs for smaller output too. Vincent 04:56, 25 May 2005 (PDT)
The large output example worked perfectly ! Excelent work! And by the way, excelent support too. Thank you very much !
I tried to catch an exception when someone tries to execute an external program, that doesn`t exists. I wasn't able to get the exception on Linux (gtk). If i compiled the Test-App for Win32 the Exception was catchable. What can i do to grap the Exceptions that should come from TProccess under Linux ? Thanks in advance Tanila