Difference between revisions of "Talk:Executing External Programs"

From Free Pascal wiki
Jump to navigationJump to search
(Dynamic Buffer for output)
 
(9 intermediate revisions by 6 users not shown)
Line 1: Line 1:
 
+
===Reading large output===
== Improved example didn't work for me ==
+
NB: use AProcess.Output.Read(Buffer'''[0]''', BUF_SIZE) for dynamic Buffer
 
 
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. [[User:Vincent|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. [[User:Vincent|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.
 

Latest revision as of 21:00, 5 March 2017

Reading large output

NB: use AProcess.Output.Read(Buffer[0], BUF_SIZE) for dynamic Buffer