Search code examples
macosshellterminalshampl

Mac Terminal script: commands inside program


I want to run a program inside terminal using a .sh script and make the script give commands to the program. This is my code:

echo "running ampl"
ampl
include test.run.txt;
python outConverter.py

The line include test.run.txt; is the command I want to run inside AMPL, but the script stops when I have opened AMPL:

Terminal window


Solution

  • You should be able to pass input to AMPL (or any other command) by redirecting input as follows:

    echo "running ampl"
    ampl << EOF
    include test.run.txt;
    EOF
    python outConverter.py
    

    This particular case can be simplified to just

    echo "running ampl"
    ampl test.run.txt
    python outConverter.py
    

    because you can pass the names of AMPL files to process as command-line arguments.