2

Here's what I have:

A script that records sound and exits when pushing ctrl+c

arecord -D plughw:0,0 -f cd -t wav -d 0 -q -r 16000 > file

This will record and record until I push ctrl+c

I want to simulate the ctrl+c action, by pushing any key (preferably one keystroke)

  • 1
    Is it important to you to actually simulate a Ctrl+C keypress, or would other methods of stopping the recording be acceptable as long as they were triggered by pressing any key? – ændrük Nov 13 '13 at 06:19
  • Any method of stopping the recording would be perfectly fine. There is more to the script, so I need it to be able to continue along without going on forever. – user215275 Nov 13 '13 at 06:32

2 Answers2

1

You can use stty in a subshell and change the setting for ctrl-c to whatever. In my example I changed it to x. After the subshell is ended or interrupted by x the setting will be restored to ^c (ctrl-c).

user@host:~# (stty intr x && arecord -D plughw:0,0 -f cd -t wav -d 0 -q -r 16000 > file); stty intr ^c

Even if you kill the process via killall acroread the setting will be restored.

chaos
  • 27,506
  • 12
  • 74
  • 77
  • Wow! I'm impressed by this one. It's not any key, but it's one line and doesn't require a enter after pushing the intr keystroke. – user215275 Nov 13 '13 at 15:25
1

Assuming you use bash as your shell(you can change the shell if its other than bash, in the first line of the script):

#!/bin/bash
arecord -D plughw:0,0 -f cd -t wav -d 0 -q -r 16000 > file &
pid_of_arecord=`pidof arecord`
read input
kill -2 $pid_of_arecord

This sends the SIGINT signal to arecord wheneven you press any key after starting the recording.

jobin
  • 27,708