I'm writing a small program in Haskell which manipulates the commands arecordmidi
and aplaymidi
to record short improvisations on my digital piano through MIDI. I will press the R key, my program will create a new subprocess with the command arecordmidi
. When I press R again, I want my recording to stop, by terminating the command arecordmidi
.
How do I terminate the arecordmidi
subprocess? If in a shell, CTRL+C would stop recording. This is what I want.
I'm using the following code to create the subprocess:
import System.Process
main = do
let rec_command = "arecordmidi -p \"CASIO USB-MIDI\" myRecording.midi"
process <- createProcess (shell rec_command)
-- I could try the following code, but the documentation of System.Process
-- says it's bad to use terminateProcess:
let (_, _, _, processHandle) = process
terminateProcess processHandle
terminateProcess
sends a SIGTERM
(terminate) signal to the process, which corresponds to the default behavior of the unix command kill
, which generally is not what you want when trying to end a process nicely.
Ctrl+C
sends the signal SIGINT
(interrupt), which many applications handle by an orderly shutdown, and in your case probably results in the arecordmidi
process saving outstanding data, and closing any pipes and files.
Looks like the way to send SIGINT
with System.Process
is with interruptProcessGroupOf
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With