Alright so using Python with windows I am trying to run a batch command which is the “move” command to move files. I am aware it can be done using the shutil in python but it gave me trouble.
move /-y "%~dp0itself.py" "C:\folder\folder2\"
That works perfectly when run alone as a batch file.
import subprocess
process = subprocess.Popen(move /-y "%~dp0sarpedon.py" "C:\Utility\Config\", shell=True, stdout=subprocess.PIPE)
process.wait()
print process.returncode
I tried adding that to the end of some other code in python but I keep getting errors it says I have invalid syntax because of the at the end of
"%~dp0sarpedon.py (")
A lot of the attempts I use to fix it end with the error:
EOL while scanning string literal.
Because the closing parentheses
(move /-y "%~dp0sarpedon.py" "C:\Utility\Config\", shell=True, stdout=subprocess.PIPE ")"
How can I fix this?
Can you specify what trouble shutil gave? Did you forget the double backslash? Or does either the file or the directory require admin privileges?
Did the following cause an error?
Running on my 64-bit Windows machine moved the file with this line.
As to why your code isn’t working — I think its because of the \”, try using double backslashes \, or the string interpreter won’t end the string. Or it will create some weird character in place of all of your separators.
Try the following with a combined string for the move and destination commands if you’re devoted to using subprocess: