userHG
userHG

Reputation: 589

ImportError with subprocess, run and PIPE in python

I'm using subprocess in python with this code :

from subprocess import run, PIPE
result = run(['/Users/{PATH-TO-SDK}/28.0.3/aapt','dump', 'badging', 'com.squareup.cash.apk'], stdout=PIPE, stderr=PIPE, check=True,
    universal_newlines=True)
version = result.stdout.split("versionName='")[1].split("'")[0]

This code used to work with Mac but when I'm using it on ubuntu I've got an error :

Traceback (most recent call last): File "ScrapInfos.py", line 11, in from subprocess import run, PIPE ImportError: cannot import name run

How can I fix this ? Thank you

Upvotes: 1

Views: 2509

Answers (1)

tstorym
tstorym

Reputation: 36

run may be defined already; use subprocess.run instead.

import subprocess 
from subprocess import PIPE

command = [
    '/Users/{PATH-TO-SDK}/28.0.3/aapt',
    'dump', 
    'badging', 
    'com.squareup.cash.apk',
]
result = subprocess.run(command, 
        stdout=PIPE, 
        stderr=PIPE, 
        check=True, 
        universal_newlines=True)

version = result.stdout
version = version.split("versionName='")[1]
version = version.split("'")[0]

Upvotes: 0

Related Questions