0

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.

karolch
  • 184
  • 4
  • 19
Manib
  • 171
  • 15
  • Generally, stdout goes to only one place. It can be streamed to your program, *or* it can be streamed to a terminal, but not both. The usual way to deal with this kind of situation is to send output to your parent process, and having that parent process be responsible for both doing the necessary analysis and passing a copy of the output along to somewhere the user can read it. – Charles Duffy Feb 13 '20 at 14:02
  • I'm using tkinter aswell so I'm assuming I can get the output and put it into a label or something for the user to see it. However what my issue was with that was if the user is transfering large files. It will run robocopy and only once robocopy has finished it will give me the output to the label for the user to see. So until then the user doesn't know about the progress of it. I also need the details within robocopy to create a log of the files which were transferred successfully (By checking for 100% next to the file(s)), source path, destination path and time. Don't mind using another way – Manib Feb 13 '20 at 14:19
  • One thing I can think of is running robocopy the first time in the terminal and after the terminal command has finished then to rerun the command to get the output in python. The second time it will skip the files/directories as they have already been copied over. If it skips all of them then I can assume they have all been installed correctly. What do you think? – Manib Feb 13 '20 at 14:33
  • Having an issue with this [here](https://stackoverflow.com/questions/60224032/making-python-wait-until-subprocess-call-has-finished-its-command) – Manib Feb 14 '20 at 12:37

0 Answers0