Hi, firstly I'm sorry for my English bad. I am working on a long-time pascal Tprocess and have resolved the problem. The output of the application can not run it in the closing process and unable to communicate. Trying to process my intention to communicate. In the meantime, a program written in Python process. I'll be glad you can be helpful in this regard. -------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20111015/b0533379/attachment.html>
Mailing lists / lazarus / 2011-10
Tprocess to communicate with applications running
11 messages · 5 people · –
- CCelâl Emre ÖZ 6
- MMichael Van Canneyt 2
- AAndrew Haines 1
- FFelipe Monteiro de Carvalho 1
- UUnknown author 1
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Hello,
Please always put some code snipets (a full minimal program would be ideal) and mention your FPC version and operating system when asking questions.
In your case also adding your question in turkish in addition to english (but please not only turkish) might be helpful too, since maybe google translate will be able to translate it. I did not understand most of your post.
Ok. thank u your answer.
I wrote a Python program. It's a xmpp client and it's running like a server. So it's always run but pascal don't get output or send input when python running.
Turkish
"Pythonda yazd???m xmpp client yaz?l?m?na, pascaldan girdi g?ndermiyor ya da ??kt? alam?yorum.
Tprocess ?al??an bir programa program kapanana kadar eri?emiyor"
CODE
procedure TForm1.Button1Click(Sender: TObject);
var python:TProcess;
cikti:TStringList;
CharBuffer: array [0..511] of char;
ReadCount: integer;
ott:string;
begin
python:=TProcess.Create(nil);
cikti := TStringList.Create;
python.CommandLine:= 'c:\python27\python.exe jabber.py';
python.Execute;
ShowMessage('b');
while python.Running do begin
ShowMessage('c');
if python.Output.NumBytesAvailable >0 then ShowMessage('A'); // ERRORR
DON'T SHOW
begin
ReadCount := Min(512, python.Output.NumBytesAvailable);
python.Output.Read(CharBuffer, ReadCount);
Write(ott, Copy(CharBuffer, 0, ReadCount));
memo1.Lines.Add(ott);
end;
end;On Sun, Oct 16, 2011 at 6:00 PM, Felipe Monteiro de Carvalho <
Show quoted text 21 lines
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20111016/07da9e8a/attachment.html>
Cel?l Emre ?Z wrote 28 lines
Do not use NumBytesAvailable.
You can do it simply as follows:
while python.Running do
begin
Repeat
readCount:=python.Output.Read(CharBuffer,512);
Write(ott, Copy(CharBuffer, 0, ReadCount));
? memo1.Lines.Add(Copy(CharBuffer, 0, ReadCount));
until (readcount<512);
end;Read will simply read as much bytes as are available.
Michael.
I've tried it but fpc has failed *Project project1.exe raised exception class external:SIGSEGV *
2011/10/16 Michael Van Canneyt
Show quoted text 60 lines
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20111016/fff5d5e6/attachment.html>
Cel?l Emre ?Z wroteI've tried it but fpc has failed *Project project1.exe raised exception class external:SIGSEGV *
Have you enabled pipes? I didn't see it anywhere.
Python.Options := [poUsePipes];
Python.Execute;More options here:
http://lazarus-ccr.sourceforge.net/docs/fcl/process/tprocessoptions.html
Regards,
Andrew
Andrew Haines wrote 9 lines
Good point.
Michael.
if I use the poUsePipes, python starts, but does not write anything on the screen. the program must write a report
Screen 1 with pipe : http://b1110.hizliresim.com/11/10/16/16687.jpg* Screen 2 with out pipe : http://b1110.hizliresim.com/11/10/16/16718.jpg *
2011/10/16
Show quoted text 27 lines
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20111016/ab442712/attachment.html>
Cel?l Emre ?Z wroteif I use the poUsePipes, python starts, but does not write anything on the screen. the program must write a report
You must use pipes, otherwise you cannot catch the output. The
Python.Options := [poUsePipes];combined with my suggestions should write something to screen.
Michael.
Show quoted text 34 lines
Ok. I've tried Python.Options := [poNoConsole,
poUsePipes,poStderrToOutPut]; and it's run successful but only problem continuous loop and it can't response to users. I've tried Application.ProcessMessages;
but don't resolve.
2011/10/16 Michael Van Canneyt
Show quoted text 58 lines
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20111016/f5f6ea87/attachment.html>
i resolve problem, thanks to everyone.
Cel?l Emre ?Z wrote 68 lines
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20111016/0c5a3f03/attachment.html>
