How to keep the terminal open after executing a C program

cgnometerminal

I'm trying to run a C program from within a python code.

cmd = 'gnome-terminal --command=./myprog'
subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)

The code executes and the terminal closes.

I want to keep the terminal open after the execution is completed without having to add any extra code in the C file e.g. prompt the user for some input.

Is there a workaround for this?

Best Answer

To keep the terminal opened until a key is pressed:

gnome-terminal -- bash -c "ls && read"

To keep the terminal opened until exit:

gnome-terminal -- bash -c "ls && bash"

Replace ls with the command you want to execute (your compiled executable file).

Note

If -- does not work, try the old (deprecated) -x approach instead:

gnome-terminal -x bash [...]
Related Question