1

I run this code:

source_path="c:\temp\\"
dest_path="c:\\temp2\\"
for Name in UserNames:
run_win_cmd("robocopy "+ source_path + Name + "* "+ dest_path)

Name in UserNames gives a name like JBlackstone, and I get the following:

b'ERROR : Invalid Parameter #2 : "emp\\Flastone*"\r\n'

Complete with the b'. No matter how I seem to format the backslashes for the command line, it ends up wrong. Here it read \temp as tab emp. If I double backslashes \\temp\\ to the \, it puts in double backslashes. If I don't it reads them as formatting chararcters. I am using run_win_cmd to call the code.

Suggestions would be much appreciated.

Ashley Mills
  • 50,474
  • 16
  • 129
  • 160
dan9126
  • 11
  • 2
  • see https://stackoverflow.com/questions/51520/how-to-get-an-absolute-file-path-in-python – Shihe Zhang Oct 27 '18 at 01:25
  • @Shihe Zhang Thank you for your response. That absoulutely was part of the problem. Also I found the following (go to the very bottom of the page, its long) and the process of escaping backslashes in Windows commands is clearly explained. [1]:(https://docs.python.org/3.5/library/subprocess.html#subprocess.PIPE) – dan9126 Oct 28 '18 at 23:26
  • You could answer your own question, or(and) mark it's a duplicate. – Shihe Zhang Oct 29 '18 at 07:03

1 Answers1

0

I just rewrote it using Popen directly which appears to be the way most people do this in python now. I also pipe d stdout and stderr to a file. The process of doing that formatted the text correctly.

Crap Phone
  • 116
  • 1
  • 2