I have a command line tool in windows that scans for devices.
It will loop through all devices in range repeating until it receives a CTRL+C command.
device1 name firmware
device2 name firmware
device3 name firmware
device1 name firmware
device2 name firmware
device3 name firmware
...
I want to stop the scan when it reaches a certain device so I can issue an update firmware command.
At the moment I can only capture the output after the CTRL+C command is issued using the following function that starts the scan, sleeps, then issues the CTRL+C command, I then catch the error and process the output in the
I tried various combinations using :
When I try the code using a command like
I have searched SO for tried anything that looks similar but nothing works for what I need.
I think I am missing something obvious or it is not possible due to the tool locking or being in a separate process not accessible by python.
Any direction or advice is appreciated!
It will loop through all devices in range repeating until it receives a CTRL+C command.
device1 name firmware
device2 name firmware
device3 name firmware
device1 name firmware
device2 name firmware
device3 name firmware
...
I want to stop the scan when it reaches a certain device so I can issue an update firmware command.
At the moment I can only capture the output after the CTRL+C command is issued using the following function that starts the scan, sleeps, then issues the CTRL+C command, I then catch the error and process the output in the
except block: command = [self.cli_tool, '-s']
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
startupinfo.wShowWindow = subprocess.SW_HIDE
stream = []
if self.check_dongle_firmware() is not False:
try:
self.proc = subprocess.Popen(
command,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL,
startupinfo=startupinfo)
time.sleep(SCAN_TIMEOUT)
os.kill(self.proc.pid, signal.CTRL_C_EVENT)
self.proc.wait()
except KeyboardInterrupt:
for line in self.proc.stdout:
stream.append(line)
for x in stream[7:]:
x = x.decode()
print(x.strip()) I want something like this: stream = []
self.proc = subprocess.Popen(
command, stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL,
startupinfo=startupinfo)
for line in self.proc.stdout:
stream.append(line)
if 'device' in line:
os.kill(self.proc.pid, signal.CTRL_C_EVENT)
self.proc.wait()This does not work though.I tried various combinations using :
universal_newlines=Truebufsize=1self.proc.communicate()[0]When I try the code using a command like
ping I have no problem and full control of the output.I have searched SO for tried anything that looks similar but nothing works for what I need.
I think I am missing something obvious or it is not possible due to the tool locking or being in a separate process not accessible by python.
Any direction or advice is appreciated!

? This was done on Ubuntu