in reply to Re: "Answer" questions in an interactive program?
in thread "Answer" questions in an interactive program?

Thanks a lot for your time!
I have 2 questions:
a) The code you kindly provided should be in 2 separate programs? I put it in one perl script, correct?
b) The old program I need to run has its executable in /usr/local/bin. Will the script need me to specify its full path?
I tried what you wrote and returned
enter file name (you must specify the file name and press Enter) Test.file do you want to specify another file name (Y/N) (you must enter N in mo +st cases and press Enter) N enter name for output file (you must specify a name for the output fil +e, eg ttt and press Enter) Result.file reading Test.file; writing Result.file
I suppose it didn't execute the external program, right? I used your code, like:
#! 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; my $progname = '/usr/local/bin/simpa96'; #--->this is the name of the + external program I need to pass the parameters to 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;

Replies are listed 'Best First'.
Re^3: "Answer" questions in an interactive program?
by BrowserUk (Patriarch) on May 11, 2010 at 11:49 UTC

    The first program is just a substitute for your real program (which I obviously do not have), soley for the purposes of demonstration.

    You don't need it. You only need (something like) the second program.

    Does that make it clearer?

    Will the script need me to specify its full path?

    Not if it is in your path. But it will do no harm to specify the full path.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.