AT has asked for the wisdom of the Perl Monks concerning the following question:
$mapfile="toy2.map"; $outfile="toy2.smv"; open(spcmap,"<",$mapfile) || die("Couldn't read $mapfile: $!"); expectsmv(); close($mapfile); sub expectsmv { my $exp = new Expect; my ($bout, $aout, $err); $exp->log_stdout(0); $exp->raw_pty(1); $exp->manual_stty(1); my $command="NuSMV -int"; $exp->spawn($command) or die "Cannot spawn $command: $!\n"; #$exp->log_file("expect_log"); # Remove the banner # $exp->send("\n"); my $patidx = $exp->expect(undef,'NuSMV > ', '-re','NuSMV\s+>\s+' ); #$exp->clear_accum(); #Setup NuSMV and load model file $exp->send("read_model -i $outfile \n"); $exp->send("process_model \n"); #$err = $exp->error; #if($err != 0){ print "Error=", $err ;} #$exp->clear_accum(); while(1) { print "B2S > "; my $cmd = <STDIN>; if($cmd =~ /\s*quit\s+/){ last; $exp->soft_close(); } elsif($cmd =~ /\s*query\s+./) { my($q, $c) = split(" ",$cmd,2); #$cmd = nusmv_q_trans($c); chomp($cmd); $exp->clear_accum(); if($cmd !~ /\b*error1\b*/){ $cmd = "check_spec -p \" $cmd \" "; print "\n $cmd \n"; $exp->send($cmd);} else { print "\n Error \n"; } #Do some pattern matching with either the simple interface my $patidx = $exp->expect(undef,'NuSMV > ', '-re','NuSMV\s+>\s+' ); $err = $exp->exp_error(); if($err != 0){ print "Error=", $err ;} else{ # print $patidx; ($bout = $exp->exp_before) =~ tr/\r//d; $err = $bout; #$bout = nusmv_res_trans($bout); print $bout; } } # end of elsif else # Not a Query { $exp->send($cmd); my $patidx = $exp->expect(undef,'NuSMV > ', '-re','NuSMV\s+>\s+' ); $err = $exp->exp_error; if($exp->error() != 0){ print $exp->error(); last;} else{ ($bout = $exp->exp_before) =~ tr/\r//d; ($aout = $exp->exp_after) =~ tr/\r//d; print $bout; } } #end of else } $exp->clear_accum(); } #end of subroutine #Routine for Translating Query into nusmv format sub nusmv_q_trans { my ($cmd) = @_; #change species names to bngl S# format # search for a species name; beginning with alphabet and replace with +S# found from hash print $cmd; #$cmd =~ s/\b([a-zA-Z])\w*\b/S$smap{$1} /g; $cmd =~ s{ \b([a-zA-Z])\w*\b } { $smap{$1} ? "S$smap{$1}" : return "error1" }xge; $cmd =~ tr/_//d; return $cmd; } sub nusmv_res_trans { my ($res) = @_; $res =~ s/\bS(\d+)\b/$spar[$1]/g; return $res; }
B2S > help Sending 'help \012' to spawn id(4) Expect::print('Expect=GLOB(0x98195cc)','help \x{a}') called at + ./expecttest.pl line 96 main::expectsmv() called at ./expecttest.pl line 7 Starting EXPECT pattern matching... Expect::expect('Expect=GLOB(0x98195cc)',10000,'NuSMV > ','-re' +,'NuSMV\s+>\s+') called at ./expecttest.pl line 99 main::expectsmv() called at ./expecttest.pl line 7 spawn id(4): list of patterns: #1: -ex `NuSMV > ' #2: -re `NuSMV\\s+>\s+' spawn id(4): Does `' match: pattern #1: -ex `NuSMV > '? No. pattern #2: -re `NuSMV\\s+>\s+'? No. Waiting for new data (10000 seconds)... spawn id(4): Does `NuSMV > ' match: pattern #1: -ex `NuSMV > '? YES!! Before match string: `' Match string: `NuSMV > ' After match string: `' Matchlist: () Returning from expect successfully. B2S > Sending ' \012' to spawn id(4) Expect::print('Expect=GLOB(0x98195cc)',' \x{a}') called at ./e +xpecttest.pl line 96 main::expectsmv() called at ./expecttest.pl line 7 Starting EXPECT pattern matching... Expect::expect('Expect=GLOB(0x98195cc)',10000,'NuSMV > ','-re' +,'NuSMV\s+>\s+') called at ./expecttest.pl line 99 main::expectsmv() called at ./expecttest.pl line 7 spawn id(4): list of patterns: #1: -ex `NuSMV > ' #2: -re `NuSMV\\s+>\s+' spawn id(4): Does `' match: pattern #1: -ex `NuSMV > '? No. pattern #2: -re `NuSMV\\s+>\s+'? No. Waiting for new data (10000 seconds)... spawn id(4): Does `NuSMV > ' match: pattern #1: -ex `NuSMV > '? YES!! Before match string: `' Match string: `NuSMV > ' After match string: `' Matchlist: () Returning from expect successfully. B2S > Sending ' \012' to spawn id(4) Expect::print('Expect=GLOB(0x98195cc)',' \x{a}') called at ./e +xpecttest.pl line 96 main::expectsmv() called at ./expecttest.pl line 7 Starting EXPECT pattern matching... Expect::expect('Expect=GLOB(0x98195cc)',10000,'NuSMV > ','-re' +,'NuSMV\s+>\s+') called at ./expecttest.pl line 99 main::expectsmv() called at ./expecttest.pl line 7 spawn id(4): list of patterns: #1: -ex `NuSMV > ' #2: -re `NuSMV\\s+>\s+' spawn id(4): Does `' match: pattern #1: -ex `NuSMV > '? No. pattern #2: -re `NuSMV\\s+>\s+'? No. Waiting for new data (10000 seconds)... spawn id(4): Does `... \012gen_ltlspec_bmc_onepb get_internal_st +atus go \012go_bmc goto_st +ate help \012history pick_s +tate print_bdd_stats \012print_clusterinfo pri +nt_current_state print_fair_states \012print_fair_trans +itions print_iwls95options print_reachable_states \012pri +nt_usage process_model quit + \012read_model read_trace reset + \012set set_bdd_parameters + show_plugins \012show_property show_trace +s show_vars \012simulate + source time \012unalias + unset usage \ +012which write_boolean_model write_flat_mod +el \012write_order \012' match: pattern #1: -ex `NuSMV > '? No. pattern #2: -re `NuSMV\\s+>\s+'? No. Waiting for new data (10000 seconds)... spawn id(4): Does `...en_ltlspec_bmc_onepb get_internal_status + go \012go_bmc goto_state + help \012history p +ick_state print_bdd_stats \012print_clusteri +nfo print_current_state print_fair_states \012p +rint_fair_transitions print_iwls95options print_reachable_states + \012print_usage process_model quit + \012read_model read_trace reset + \012set set_bdd_parameters sho +w_plugins \012show_property show_traces + show_vars \012simulate source + time \012unalias uns +et usage \012which + write_boolean_model write_flat_model \012write_orde +r \012NuSMV > ' match: pattern #1: -ex `NuSMV > '? YES!! Before match string: `... \012gen_ltlspec_bmc_onepb get_inte +rnal_status go \012go_bmc + goto_state help \012history + pick_state print_bdd_stats \012pri +nt_clusterinfo print_current_state print_fair_states + \012print_fair_transitions print_iwls95options print_r +eachable_states \012print_usage process_model + quit \012read_model read_tr +ace reset \012set + set_bdd_parameters show_plugins \012show_pr +operty show_traces show_vars + \012simulate source time \0 +12unalias unset usage \012w +hich write_boolean_model write_flat_model \012writ +e_order \012' Match string: `NuSMV > ' After match string: `' Matchlist: () Returning from expect successfully. add_property alias bmc_setup bmc_simulate build_boolean_model build_flat_model build_model check_fsm check_invar check_invar_bmc check_ltlspec check_ltlspec_bmc check_ltlspec_bmc_onepb check_property check_spec check_wff compute compute_reachable dynamic_var_ordering echo encode_variables flatten_hierarchy gen_invar_bmc gen_ltlspec_bmc gen_ltlspec_bmc_onepb get_internal_status go go_bmc goto_state help history pick_state print_bdd_stats print_clusterinfo print_current_state print_fair_states print_fair_transitions print_iwls95options print_reachable_st +ates print_usage process_model quit read_model read_trace reset set set_bdd_parameters show_plugins show_property show_traces show_vars simulate source time unalias unset usage which write_boolean_model write_flat_model write_order B2S >
|
---|
Replies are listed 'Best First'. | |
---|---|
Problem with expect.pm
by AT (Initiate) on Jul 13, 2005 at 17:44 UTC | |
Re: expect.pm problem
by graff (Chancellor) on Jul 14, 2005 at 03:32 UTC | |
by AT (Initiate) on Jul 14, 2005 at 16:16 UTC |