Add popen function
This commit is contained in:
parent
d22873f53b
commit
2ac1415975
|
@ -39,6 +39,7 @@ import sys
|
|||
import tempfile
|
||||
import threading
|
||||
import time
|
||||
import traceback
|
||||
import zipfile
|
||||
|
||||
from collections import OrderedDict
|
||||
|
@ -170,6 +171,10 @@ PC = platform.node()
|
|||
DESKTOP = os.environ.get('DESKTOP_SESSION', '')
|
||||
INFO_DEBUG = f"{sys.version}\n\n{platform.platform()}\n\n" + '\n'.join(sys.path)
|
||||
|
||||
PYTHON = 'python'
|
||||
if IS_WIN:
|
||||
PYTHON = 'python.exe'
|
||||
|
||||
_MACROS = {}
|
||||
_start = 0
|
||||
|
||||
|
@ -302,7 +307,7 @@ def catch_exception(f):
|
|||
except Exception as e:
|
||||
name = f.__name__
|
||||
if IS_WIN:
|
||||
debug(traceback.format_exc())
|
||||
msgbox(traceback.format_exc())
|
||||
log.error(name, exc_info=True)
|
||||
return func
|
||||
|
||||
|
@ -535,7 +540,7 @@ def run(command, capture=False, split=True):
|
|||
return subprocess.check_output(command, shell=True).decode()
|
||||
|
||||
cmd = shlex.split(command)
|
||||
result = subprocess.run(cmd, capture_output=capture, text=True)
|
||||
result = subprocess.run(cmd, capture_output=capture, text=True, shell=IS_WIN)
|
||||
if capture:
|
||||
result = result.stdout
|
||||
else:
|
||||
|
@ -543,15 +548,15 @@ def run(command, capture=False, split=True):
|
|||
return result
|
||||
|
||||
|
||||
# ~ def popen(command, stdin=None):
|
||||
# ~ try:
|
||||
# ~ proc = subprocess.Popen(shlex.split(command), shell=IS_WIN,
|
||||
# ~ stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
# ~ for line in proc.stdout:
|
||||
# ~ yield line.decode().rstrip()
|
||||
# ~ except Exception as e:
|
||||
# ~ error(e)
|
||||
# ~ yield (e.errno, e.strerror)
|
||||
def popen(command):
|
||||
try:
|
||||
proc = subprocess.Popen(shlex.split(command), shell=IS_WIN,
|
||||
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
for line in proc.stdout:
|
||||
yield line.decode().rstrip()
|
||||
except Exception as e:
|
||||
error(e)
|
||||
yield (e.errno, e.strerror)
|
||||
|
||||
|
||||
def sleep(seconds):
|
||||
|
@ -4039,7 +4044,13 @@ class Paths(object):
|
|||
|
||||
@classproperty
|
||||
def python(self):
|
||||
return sys.executable
|
||||
if IS_WIN:
|
||||
path = self.join(self.config('Module'), PYTHON)
|
||||
elif IS_MAC:
|
||||
path = self.join(self.config('Module'), '..', 'Resources', PYTHON)
|
||||
else:
|
||||
path = sys.executable
|
||||
return path
|
||||
|
||||
@classmethod
|
||||
def dir_tmp(self, only_name=False):
|
||||
|
|
Loading…
Reference in New Issue