Skip to content Skip to sidebar Skip to footer

Command Not Works In Subprocess Or Os.popen But Works In Terminal

I've tried lots of methods to run my shell script but none of these works from python3 script. The command is very simple and works in terminal without problem. Here's what I've tr

Solution 1:

Ok, now it works with these changes:

Here's the shell script (commonBash.sh):

name=libreoffice
dat=$(dpkg-query -W $name)
echo"Checking for "$name": "echo"$dat"if [ "" == "$dat" ]; thenecho"No "$name". Setting up "$name"..."elseecho$name" is installed already."fi

Here's the python script:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import os

dat = os.popen('bash commonBash.sh').read()
print(dat)
if"No"in str(dat):
    print('Not found')
    status = 'Install'else:
    print('Found')
    status = 'Remove'

And here's the output (now it's correct):

dpkg-query:nopackagesfoundmatchinglibreofficeChecking for libreoffice:Nolibreoffice.Settinguplibreoffice...Notfound

Post a Comment for "Command Not Works In Subprocess Or Os.popen But Works In Terminal"