I want to pass some variable in command prompt with some other text as well. I tried with this code and it doesn't work. Any hints what I might be doing wrong or what should I do instead?
There is a variable "v" which stores a URL and I want to pass this URL in the cmd with some other parameters.I have this code right now.
working_directory = os.getcwd()
p = subprocess.Popen(['ffmpeg -i 'v' -c copy getit.mkv'], cwd=working_directory)
p.wait()
But, it seems like this isn't working. I can't pass the variable "V". It just pastes V when I remove the quotes
Pass the command as a list like below:
working_directory = os.getcwd()
p = subprocess.Popen(['ffmpeg', '-i', v, '-c' 'copy' 'getit.mkv'], cwd=working_directory)
p.wait()
Or use shlex.split() which should handle this properly:
cmd = 'ffmpeg -i "{}" -c copy getit.mkv'.format(v)
p = subprocess.Popen(shlex.split(cmd), cwd=working_directory)
To pass a variable into a string you can use format method of string:
v = 'file.avi'
p = subprocess.Popen(["ffmpeg -i {} -c copy getit.mkv".format(v)], cwd=working_directory)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With