I have a Perl script to call another program. One section looks like this:
open(AMPL,"|ampl");
select(AMPL);
printf "option solver cplex;\n";
printf "var x1;\n"
printf "var x2;\n"
printf "minimize z: 3*x1 + 2*x2;\n";
printf "another_command;\n";
printf "data $ARGV[0];\n";
# More printfs
close(AMPL);
This code fails silently if instructions passed to ampl
(that is, AMPL) are incorrect. Can the failures be either printed to STDERR or otherwise caught to abort the script?
EDIT: To clarify, this code pipes into an interactive session with the AMPL interpreter:
$ ampl
ampl: option solver cplex;
>>> var x1;
>>> var x2;
>>> minimize z: 3*x1 + 2*x2;
>>> another_command;
>>> data foo;