Home > OS >  How do I use multiple variables and strings within an os.system() command?
How do I use multiple variables and strings within an os.system() command?

Time:10-05

im trying to make a simple program that downloads a file. im having a problem with the command part. here is the code:

import os

#gather user input
print("hello! welcome to the website dowloader! paste in the url(including the http 
part) and type in the file name!)")
url = input("website url: ")
filename = input("the filename:")

#the command i want run. for example, if the url was "https://example.com" and the 
#filename was "example.html"
#then i would want the command run to be: 'curl https://example.com --output 
#example.html'
cmd = str("curl ", url," --output ", filename)
os.system(cmd)

CodePudding user response:

str("curl ", url," --output ", filename) are you asking how to concatenate strings? You do that with the operator, but usually, formatting strings would be eaiser here, so just f"curl {url} --output {filename}". Also, you should probably be using subprocess instead of os.system

answer by @juanpa.arrivillaga

  • Related