Reputation: 75
I am trying to send a command prompt command using Python Subprocess. I haven't been able to get my code to send "\" in the command. I usually specify directions as:
"D:\\deneme\\1"
or
r"D\deneme\\1"
So, I tried both as:
import subprocess
subprocess.run(["copy /b D:\\deneme\\1\\*.ts D:\\deneme\\1\\1.ts"])
But the string is sent as it is so I get the error, "FileNotFoundError: [WinError 2] The system cannot find the file specified". I also tried using the unicode number (\u005C), but it also returns double "\". What should I do in this case?
Upvotes: 1
Views: 1651
Reputation: 531185
Your system shell is try to find a command with the name copy /b D:\\...
, not run copy
with 3 arguments. Either drop the list:
subprocess.run("copy /b D:\\deneme\\1\\*.ts D:\\deneme\\1\\1.ts")
or pass a proper list containing the command name and its arguments as separate elements.
subprocess.run(["copy", "/b", "D:\\deneme\\1\\*.ts", "D:\\deneme\\1\\1.ts"])
Upvotes: 1