I try to get some dependency stuff on pacman automated via python. What I want to issue in the shell (and get output from) is:
pacman -Si [a_package] | grep Conflicts | awk -F: '{print $2}'
So this is my python code:
getconflicts1 = "pacman -Si"
getconflicts2 = "| grep Conflicts | awk -F: '{print $2}'"
pkgs = # an example package list
for x in range (1,2):
getconflicts = getconflicts1 + pkgs[x] + getconflicts2
process2 = subprocess.Popen(getconflicts.split(), stdout=subprocess.PIPE)
conflicts = process2.communicate()[0]
print(conflicts)
However pacman says "invalid option -- F" when I use the python program, whereas issueing the command in the shell directly works.
This:
print(getconflicts.split())
gives me:
['pacman', '-Si', 'frameworkintegration', '|', 'grep', 'Conflicts', '|', 'awk', '-F:', "'{print", "$2}'"]
I'm kinda new to python and subprocesses in python even more, so do you have a hint on how to do that correctly?