问题
I'm trying to have a command window open and then once the command has been executed to take the output of it into a variable. The issue that I'm having is that when I use the below command I get an empty string: self.srcEntry.get()
and self.dstEntry.get()
are the sources and destination folders for robocopy.
output = Popen(["start", "cmd", "/K", "RoboCopy.exe", f"{self.srcEntry.get()}", f"{self.dstEntry.get()}", "*.*", "/E", "/Z", "/MT:8"], stdout=PIPE, stdin=PIPE, shell=True)
print(output.communicate()[0].decode('utf-8'))
Also the program pauses until the command window has been closed (I don't have an issue with that). However when I use:
output = Popen(["RoboCopy.exe", f"{self.srcEntry.get()}", f"{self.dstEntry.get()}", "*.*", "/E", "/Z", "/MT:8"], stdout=PIPE, stdin=PIPE, shell=True)
print(output.communicate()[0].decode('utf-8'))
I can get the output but not the command window. This is an issue as if I have a big file to transfer over then I won't know how far it's gotten until it has actually finished.
来源:https://stackoverflow.com/questions/60208196/using-subprocess-to-show-a-command-window-and-get-the-text-from-the-window-after