Rename read func
This commit is contained in:
parent
0bc10b7dc0
commit
69d333ff9b
3 changed files with 26 additions and 3 deletions
|
|
@ -69,7 +69,7 @@ class Shell:
|
|||
"""
|
||||
Run a shell command and show the output as it runs
|
||||
"""
|
||||
def non_block_read(output):
|
||||
def read_stream(output):
|
||||
fd = output.fileno()
|
||||
fl = fcntl.fcntl(fd, fcntl.F_GETFL)
|
||||
fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)
|
||||
|
|
@ -87,10 +87,10 @@ class Shell:
|
|||
universal_newlines=True
|
||||
) as proc:
|
||||
while proc.poll() is None:
|
||||
err = non_block_read(proc.stderr)
|
||||
err = read_stream(proc.stderr)
|
||||
if err != "" and not suppress_message:
|
||||
self.error(err.strip(), end="\n\r")
|
||||
output = non_block_read(proc.stdout)
|
||||
output = read_stream(proc.stdout)
|
||||
if output != "" and not suppress_message:
|
||||
self.info(output.strip(), end="\n\r")
|
||||
full_output += output
|
||||
|
|
|
|||
16
test.py
Normal file
16
test.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
try:
|
||||
from adafruit_shell import Shell
|
||||
except ImportError:
|
||||
raise RuntimeError("The library 'adafruit_shell' was not found. To install, try typing: sudo pip3 install adafruit-python-shell")
|
||||
|
||||
shell = Shell()
|
||||
shell.group="Blinka"
|
||||
|
||||
def main():
|
||||
#shell.clear()
|
||||
print("Running test")
|
||||
shell.run_command("./test.sh")
|
||||
|
||||
# Main function
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
7
test.sh
Executable file
7
test.sh
Executable file
|
|
@ -0,0 +1,7 @@
|
|||
#! /bin/bash
|
||||
>&2 echo This should go to stderr
|
||||
echo Interactive Test
|
||||
>&2 echo This should also go to stderr
|
||||
read -p "Hello, who am I speaking to? " NAME
|
||||
echo It\'s Nice to meet you $NAME
|
||||
|
||||
Loading…
Reference in a new issue