My Scala script creates subprocesses like this:
val exitValue = Process(Seq("bash", "-c", command), dir) ! processLogger
with command being e.g. "mvn clean package"
or for testing of this issue "sleep 20"
.
For some reason my script has to intercept SIGINT, because the user might have meant “copy” instead of “stop it” (really happens from time to time). I achieved this by adding a signal handler like this:
Signal.handle(new Signal("INT"), this)
override def handle(sig: Signal)
{
log.warn("Ignoring SIGINT (Ctrl+C). Press [Esc] instead.")
}
However when a subprocess is running this does not work, because CTRL+C makes it stop. What can I do so that the subprocess ignores SIGINT? I found a solution for Python: Python: How to prevent subprocesses from receiving CTRL-C / Control-C / SIGINT Is there something similar for Scala?