Douglas Wade [EMAIL PROTECTED] wrote:
>I have just started to use perl/Tk and loving it. I want to launch the
>script and have the shell/cmd window results (std out) display in a
>widget like the text widget and not in the shell/cmd. Is this
>possible?

Yes. Just capture the results of the command and insert
them to the end of a text widget.

  my $cmd = "mycommand -options args";
  my $results = `$cmd`;
  $text->insert( 'end', $result );

It is trickier if you want to do it in real time
(i.e. not waiting for "mycommand" to complete).

  my $cmd = "mycommand -options args";
  my $results = '';
  open( CMD, "$cmd|" ) or die "*** Trouble opening command '$cmd' : $!\n";
  while ( <CMD> )
  {
    $results .= $_;
    $text->insert( 'end', $_ );
  }
  close( CMD ) or die "*** Trouble closing command '$cmd' : $!\n";

Note: in both cases, $results ends up with all of the
command's output to its stdout. Some systems will also
let you capture stderr mixed in via:

  my $results = `$cmd 2>&1`;

or

  open( CMD, "$cmd 2>&1 |" ) or die "*** Trouble opening command '$cmd' :
$!\n";

If you positively need separate stdout and stderr from the
child command, then you will need to use IPC::Open3 .

--
Mike Arms

_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to