In bash how can I issue a command to a running process I just started?

For example;

# Start Bluez gatttool then Connect to bluetooth device 
gatttool -b $MAC -I
connect # send 'connect' to the gatttool process?

Currently my shell script doesn't get to the connect line because the gatttool process is running.

  • 1
    you can try echo "connect" | gatttool -b $MAC -I – mazs May 25 '16 at 6:43
  • @mazs I need to send about 10 commands to gatttool. Would that still work? Could I send one long string with many different commands? – sazr May 25 '16 at 6:45
  • 1
    nope....in that case try using expect – mazs May 25 '16 at 6:45
  • 2
    Not sure what commands do you want to execute, but it seems like you can use gatttool in non-interactive mode as well, that would be simpler than writing an expect script. Check here for example : humbug.in/2014/… – mazs May 25 '16 at 6:50
  • i've added the /expect tag to your question. click on it to search for other questions with that tag. – cas May 25 '16 at 8:22

This works!

you can try

echo "connect" | gatttool -b $MAC -I

Full credit to mazs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.