简体   繁体   中英

How to pass variable name in subprocess command

import subprocess result = subprocess.call('"C:\Users\user\Desktop\Install Exe\download.exe" /S norestart ', shell=True) print(result)

This is something hardcode in the command, I want to pass this path in the variable and want variable instead of the path

Can we do this thing?

Just use

subprocess.run(["arg1", "arg2", "arg3"])

so say I wanted to move a file from "/home/myfile.txt" to "/home/data" which accepts the arguments sourcefile and destination folder I would do

subprocess.run(["mv", "/home/myfile.txt", "/home/data"])

any of these strings can be variables and the strings can be f-string formatted also

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM