I use Leiningen REPL that uses SIGINT to interrupt currently running code and to output a new prompt. The REPL can be stopped using SIGHUP or SIGKILL. I don’t actually run anything in the REPL – I just use it for some pre-defined side-effects.
The problem is that IntelliJ IDEA can only send SIGINT when it exits to the processes that it has started. So if I forget to kill a REPL started from IDEA, there’ll be a dandling process that I have to kill manually.
Is it possible to write a shell script that starts the REPL, gives it some dummy stdin/stdout (otherwise, REPL immediately quits), and waits for the process to end, while also forwarding it all signals, transforming SIGINT into SIGHUP or SIGKILL?
Advertisement
Answer
This Python code does what’s needed:
from subprocess import call import sys try: call(sys.argv[1:]) except KeyboardInterrupt: pass
All its parameters are the command line that you want to be executed. The running application will always be closed by SIGINT
.