So adding $| = 1 to the program I was trying to run helped.
This might be good for now for demo purposes but I guess this needs to
be solved somehow by faking a terminal on my end?
Gabor
On Sun, Jul 20, 2008 at 11:56 AM, Mattia Barbon <[EMAIL PROTECTED]> wrote:
> Gabor Szabo wrote:
>>
>> On Thu, Jul 17, 2008 at 12:05 PM, Huub Peters <[EMAIL PROTECTED]> wrote:
>>>
>>> Gabor Szabo wrote:
>>>>
>>>> So I am trying to write an editor using Wx.
>>>> The basic editing is in place, now comes the really interesting part.
>>>>
>>>> I would like to run the script being edited and provide a way for the
>>>> user to interact with it.
>>>> Basicall I'd like to have a console window in my application where
>>>> that is connected to
>>>> the STD IN/OUT/ERR to an external application.
>>>>
>>>> Any recommendation how should I do that?
>>>>
>>>> Gabor
>>>>
>>>>
>>> I think you could use Wx::Perl::ProcessStream for that. I've never used
>>> it but somebody ones showed me it's usage.
>>> I think it was designed to help getting a GUI on top of a command line
>>> program.
>>
>>
>> I tried this and while it looks good actually I have not received any of
>> the
>> STDOUT events until the external program finished.
>
> Might be just a buffering issue, AFAICR STDOUT is line-buffered
> only when directly connected to a terminal. Compare:
>
> $ perl test.pl
>
> and
>
> $ perl test.pl | cat
>
>> In addition the lines I received lack the trailing newline from the
>> actual output.
>
> If i read the code correctly, it's Wx::Perl::ProcessStream
> that is stripping newlines before sending the event.
>
> HTH,
> Mattia
>
>> The external program is just the following perl script:
>>
>> #!perl
>> use strict;
>> use warnings;
>>
>> my $n = 10;
>> print "First line\n";
>> print "Going to sleep $n seconds\n";
>> sleep $n;
>> print "Finished sleeping\n";
>>
>> and I am trying it on Ubuntu.
>>
>> The code I used:
>>
>> use base 'Wx::Frame';
>>
>> sub new {
>> ...
>> EVT_WXP_PROCESS_STREAM_STDOUT( $self, \&evt_process_stdout);
>> }
>>
>> on_run {
>> my ($self) = @_;
>> $proc = Wx::Perl::ProcessStream->OpenProcess("$^X file.pl",
>> 'MyName1', $self);
>> }
>> sub evt_process_stdout {
>> my ($self, $event) = @_;
>>
>> $event->Skip(1);
>> my $process = $event->GetProcess;
>> my $line = $event->GetLine;
>> $output->AppendText($line . "\n");
>>
>> return;
>> }