49
49
line = fp .readlines ()
50
50
DEVICE_PREFIX = "/dev/" + line [0 ]
51
51
52
-
53
- # runs command, exit if stderr is written to, returns stdout otherwise
54
- # input: cmd (str), output: output of cmd (str)
55
- def run_command (cmd ):
52
+ # runs command, exit if stderr is written to and abort argument is ture, returns stdout, stderr otherwise
53
+ # input: cmd (str, bool), output: output of cmd (str) and error of cmd (str) if abort is not true
54
+ def run_command (cmd , abort = True ):
56
55
proc = subprocess .Popen (cmd , stdout = subprocess .PIPE , stderr = subprocess .PIPE , shell = True )
57
56
output = proc .stdout .read ()
58
57
error = proc .stderr .read ()
59
- if error != "" :
58
+ if abort and error != "" :
60
59
click .echo ("Command resulted in error: {}" .format (error ))
61
60
sys .exit (ERR_CMD )
62
- return output
61
+ return output if abort else ( output , error )
63
62
64
63
# returns a list of all lines
65
64
def getAllLines ():
@@ -76,7 +75,7 @@ def getAllLines():
76
75
77
76
# Querying device directory to get all available console ports
78
77
cmd = "ls " + DEVICE_PREFIX + "*"
79
- output = run_command (cmd )
78
+ output , _ = run_command (cmd , abort = False )
80
79
availableTtys = output .split ('\n ' )
81
80
availableTtys = list (filter (lambda dev : re .match (DEVICE_PREFIX + r"\d+" , dev ) != None , availableTtys ))
82
81
for tty in availableTtys :
0 commit comments