Alberto Zaccagni
Alberto Zaccagni

Reputation: 31590

Send a command to a process

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?

Upvotes: 1

Views: 1696

Answers (2)

psihodelia
psihodelia

Reputation: 30522

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

Upvotes: 0

JasonSmith
JasonSmith

Reputation: 73752

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).

Upvotes: 4

Related Questions