You are not logged in.
Pages: 1
I want to be able to call a command from my python script. my problem seem to big with exporting variable to this one.
e.g: i got a variable that give me the name of name of the package to install. (pacman, for example)
from subprocess import call
call(["pacman -S commando[package-1]"])
-----------------------------------> my variable
Thanks.
Last edited by j2lapoin (2015-08-09 21:13:33)
Offline
You should have asked this in the "Programming & Scripting" sub-forum.
Pass your command as a list with multiple items or split it up. Example:
call(["pacman", "-S", "your_package"])
or
call("pacman -S your_package".split())
Offline
That what i was looking for:
subprocess.call("sudo pacman -R " + commando[numo-1], shell=True)
It's now solved:
Thank you. but I still have the famous getch() puzzle in mind. famous termios is nowhere.
Offline
You should have asked this in the "Programming & Scripting" sub-forum.
Pass your command as a list with multiple items or split it up. Example:
call(["pacman", "-S", "your_package"])
or
call("pacman -S your_package".split())
I think that the OP wants to pass a variable name as an argument instead of a string of the package name. In this case the following can be used:
var1 = "your_package"
call(["pacman", "-S", var1])
Edit: By the time I posted the thread was solved .
Last edited by baion baion (2015-08-09 21:16:50)
Offline
That what i was looking for:
subprocess.call("sudo pacman -R " + commando[numo-1], shell=True)
It's now solved:
Thank you. but I still have the famous getch() puzzle in mind. famous termios is nowhere.
Don't use shell=True, there is no sane reason to use it and it comes with some big downsides (like arbitary code execution)
You probably want to check the return code to see if it actually worked or not.
Evil #archlinux@libera.chat channel op and general support dude.
. files on github, Screenshots, Random pics and the rest
Offline
Pages: 1