How it works...

The run() function executes the subprocess specified in the array of arguments. By default, the result contains only the return code of the process, so we also pass the stdout option with the PIPE constant to indicate that the standard output stream should be piped.

We call this function with the keyword argument—shell—set to True to avoid opening a new console for the ping subprocess:

    def run(self):
self.result = subprocess.run(["ping", self.ip], shell=True,
stdout=subprocess.PIPE).stdout

Finally, when the main thread verifies that this operation has finished, it prints the output to the Text widget:

    def poll_thread(self, thread):
if thread.is_alive():
self.after(100, lambda: self.poll_thread(thread))
else:
self.button.config(state=tk.NORMAL)
self.output.delete(1.0, tk.END)
self.output.insert(tk.END, thread.result)
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset