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?
subprocessmodule receives the command as a list of parts, not as a strings string in a list. You should try:subprocess.run(['copy', '/b', r'D:\deneme\1\*.ts', r'D:\deneme\1\1.ts']). I'm not a Windows user, butcopymight needshell=Trueto be set. And BTW, there are direct options to copy something in Python.