Problems executing commands with (') character in python -
i'm doing program copies files music playlist. execute command this:
command = 'cp "%s" "%s"' % (songpath,plpath) os.system(command)
the problem when execute if song's path has ' character command can not executed. says:
cp: cannot stat `/home/myname/music/oasis/(what\'s story) morning glory/03 wonderwall.mp3': no such file or directory
i checked songpath , has no \ character before ' know how avoid program adding \ character?
thank in advance!
use subprocess.call
instead:
ret_val = subprocess.call(['cp',songpath,plpath])
this avoids shell arguments should passed cp
in exact form gave them.
Comments
Post a Comment