#!/usr/bin/env perl # This script shows a problem with Maple and pty's. Usually the input is # echoed twice, hence the regexp /.*?EndOfInput:.*?EndOfInput:/ below. # But the input is sometimes echoed only once (at a random iteration), # with the consequence that this script freezes. use strict; use IPC::Run; my ($pty, $ptyin, $ptyout); my @maple = ($ENV{'MAPLE'} || 'maple', '-q', '-s'); $pty = IPC::Run::start(\@maple, 'pty>', \$ptyout); sub maple_wr { warn "--> maple_wr(@_)\n"; my $in = "@_ EndOfInput:\n"; $ptyin = $in; pump $pty while length $ptyin || ($ptyout =~ tr/\r//d, warn("--> [$ptyout]\n"), $ptyout !~ s/.*?EndOfInput:.*?EndOfInput://s); warn "--> maple_wr OK\n"; } sub maple_rd { @_ and &maple_wr(@_); pump $pty while $ptyout !~ s/^\s*(\S.*?)\s*$//; warn "--> maple_rd [$1]\n"; return $1; } &maple_rd("interface(prettyprint=0,screenwidth=9999): Digits := 60: 1;") == 1 or die; my $e = "1.0"; foreach (1..300) { warn "--> Iteration $_\n"; $e = "cos($e)"; &maple_rd("$e;") or die; } # $Id: pty-bug 11877 2006-04-14 19:52:38Z lefevre $