Pretend that this is your old program asking the questions. It doesn't do anything except ask them, read the answers and print out the names it read:
#! perl -slw use strict; print "enter file name (you must specify the file name and press Ente +r)"; chomp( my $infile = <STDIN> ); print "do you want to specify another file name (Y/N) (you must enter +N in most cases and press Enter)"; chomp( my $another = <STDIN> ); print "enter name for output file (you must specify a name for the out +put file, eg ttt and press Enter)"; chomp( my $outfile = <STDIN> ); print "reading $infile; writing $outfile"; exit 99;
Then you can drive that program from perl using something like this:
#! perl -slw use strict; my $progname = 'junk33'; my $pid = open CMD, '|-', $progname or die $!; print CMD 'myInfile'; print CMD 'N'; print CMD 'myOutfile'; close CMD; waitpid $pid, 0; print "$progname ended: status: ", $? >>8;
And when you run that, you'll see:
c:\test>junk32 enter file name (you must specify the file name and press Enter) do you want to specify another file name (Y/N) (you must enter N in mo +st cases and press Enter) enter name for output file (you must specify a name for the output fil +e, eg ttt and press Enter) reading myInfile; writing myOutfile junk33 ended: status: 99
In reply to Re: "Answer" questions in an interactive program?
by BrowserUk
in thread "Answer" questions in an interactive program?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |