tags:

views:

91

answers:

2

Using bash, is it possibile to send the equivalent of a space bar stroke to a process? If so, how can that be done?

Edit to clarify a bit what I want to achieve: let's say I've got an mplayer process running and I want to pause the execution of the current song, how would I achieve this?

+4  A: 

You can direct standard I/O to it. If you are using Bash, then you probably have other GNU tools. GNU Coreutils has an echo command that can output pretty much anything. For example:

$ echo -n ' ' | some_command

However if you need an actual TTY (terminal) and you have more sophisticated requirements, look into expect, which can do nearly anything a human can (except think).

jhs
I've edited my question, now I think it's clearer, sorry for being unclear
Alberto Zaccagni
Expect could do that. You'll have to do some programming to communicate to Expect when it should pause (e.g. IR remote triggers some program that signals expect). But considering you are on Stack Overflow I think that is exactly what you want.
jhs
Excellent, till now I've used expect only to provide password to some scripts, I'll check its man page, thanks :)
Alberto Zaccagni
The Perl and Python versions are (IIRC) re-implementations. So you could get as creative as you like with them, such as using IPC or some other signalling system.
jhs
I don't know neither of the two, this task was a mean to improve my bash skills :P, but thank you for your suggestion.
Alberto Zaccagni
Strictly speaking, unless you call `/bin/echo` (or you have done `enable -n echo` or defined a function or alias named "echo"), you are executing the Bash builtin called "echo". They function slightly differently.
Dennis Williamson
Thanks for poiting that out, I did not know it.
Alberto Zaccagni
A: 

You can send a signal to a process using kill command. Try man kill for more info.

psihodelia