2

My students and I are using gcc to compile programs which ask a series of questions then display a result. Right now if we are running a program called "main" for example, we have to open a terminal window then type: ./Programs/main

We would like to be able to distribute these to other students who don't know how to use the terminal, so that they can just double-click on a file.

I have tried to create a .command or .sh file that does this, but they will do "exit;" before the program can get input. I also tried to use Automator, but this also exits before the program can get input.

1

When you double-click a .command file, Terminal.app will open, and execute /path/to/file.command ; exit; which means it will execute the content of the file.command script, and THEN exit.

If your Terminal is exiting before your executable can receive input, that seems to indicate that either your .command is not calling your executable correctly, or your executable somehow doesn't wait to receive input before exiting.

To be able to help you further, you'd need to provide an example .c/.cpp file to compile, and the content of your .command file.

I myself tried with a .command file that contains only:

$HOME/Downloads/go.sh

And I was able to ask for input in go.sh (using read -p) before the Terminal exited.

-1

Add a "sleep" command to pause the script's execution.

Sleep 5

Will pause for 5 seconds.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .