Okay ... I spent WAY too much time on this but I've been having fun. I think some folks will get some use out of what I've (almost) put together. I've run into a Python issue I can't seem to figure out though. I thought one of you fine folks would be able to help. Here's how to recreate the issue:
Create a file named "test.sh:"
Code:
#!/bin/bash
python ./test.py
And a file named "test.py:"
Code:
#!/usr/bin/python
name = raw_input("What is your name? ")
print "Hello, %s." % name
If you call "test.sh" normally, it works as expected:
Code:
pi@raspberrypi:~ $ ./test.sh
What is your name? Lee
Hello, Lee.
pi@raspberrypi:~ $
However if you pipe "test.sh" through a bash shell (it would take forever to explain why I want to do this, just take for granted for a minute it has to be this way) it does not wait on the raw_input:
Code:
pi@raspberrypi:~ $ cat ./test.sh | sudo bash
What is your name? Hello, .
pi@raspberrypi:~ $
This one is driving me crazy ... anyone have any ideas? When I had a similar issue with a bash script calling a bash script I fixed it by redirecting /dev/tty to the read command like this:
Code:
read -p "What is your name? " name < /dev/tty
... but I'm at a loss to figure this out in Python.
I've even been contemplating scheduling the python job, and looping until I can read a semaphore from it in the bash script, but that seems awful heavy-duty for what I'm doing.
A (virtual) beer for the person who knows how to get past this!