本文整理匯總了Python中subprocess.STDOUT屬性的典型用法代碼示例。如果您正苦於以下問題:Python subprocess.STDOUT屬性的具體用法?Python subprocess.STDOUT怎麽用?Python subprocess.STDOUT使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類subprocess
的用法示例。
在下文中一共展示了subprocess.STDOUT屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _get_terminal_size_tput
# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import STDOUT [as 別名]
def _get_terminal_size_tput(self):
# get terminal width
# src: http://stackoverflow.com/questions/263890/how-do-i-find-the-width-height-of-a-terminal-window
try:
cols = int(
subprocess.check_output(
shlex.split("tput cols"), stderr=subprocess.STDOUT
)
)
rows = int(
subprocess.check_output(
shlex.split("tput lines"), stderr=subprocess.STDOUT
)
)
return (cols, rows)
except:
pass
示例2: convert_image
# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import STDOUT [as 別名]
def convert_image(inpath, outpath, size):
"""Convert an image file using ``sips``.
Args:
inpath (str): Path of source file.
outpath (str): Path to destination file.
size (int): Width and height of destination image in pixels.
Raises:
RuntimeError: Raised if ``sips`` exits with non-zero status.
"""
cmd = [
b'sips',
b'-z', str(size), str(size),
inpath,
b'--out', outpath]
# log().debug(cmd)
with open(os.devnull, 'w') as pipe:
retcode = subprocess.call(cmd, stdout=pipe, stderr=subprocess.STDOUT)
if retcode != 0:
raise RuntimeError('sips exited with %d' % retcode)
示例3: manage
# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import STDOUT [as 別名]
def manage():
def call(*args, **kwargs):
ignore_errors = kwargs.pop("ignore_errors", False)
assert not kwargs
cmd = [
sys.executable,
os.path.join(os.path.dirname(__file__), "testprj", "manage.py"),
] + list(args)
try:
return subprocess.check_output(cmd, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
if not ignore_errors:
raise
return e.output
return call
示例4: _run_command
# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import STDOUT [as 別名]
def _run_command(cmd, timeout_secs=300):
""" Runs a command with a specified timeout.
Args:
cmd : list of string
The command with arguments to run.
timeout_secs: integer
The timeout in seconds
Returns:
Returns the process and the output as a pair.
"""
proc = subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
for i in range(timeout_secs):
sleep(1)
if proc.poll() is not None:
(out, _) = proc.communicate()
return proc, out.decode('utf-8')
proc.kill()
return proc, "Timeout of %s secs exceeded." % timeout_secs
開發者ID:awslabs,項目名稱:dynamic-training-with-apache-mxnet-on-aws,代碼行數:27,代碼來源:straight_dope_test_utils.py
示例5: _run
# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import STDOUT [as 別名]
def _run(self, *args, **kwargs):
cmd = [self.binary, '-j', self.parallelism]
if mx.get_opts().very_verbose:
cmd += ['-v']
cmd += args
out = kwargs.get('out', mx.OutputCapture())
err = kwargs.get('err', subprocess.STDOUT)
if mx.get_opts().verbose:
if callable(out) and '-n' not in args:
out = mx.TeeOutputCapture(out)
if callable(err):
err = mx.TeeOutputCapture(err)
try:
rc = mx.run(cmd, nonZeroIsFatal=False, out=out, err=err, cwd=self.build_dir)
except OSError as e:
if e.errno != errno.EACCES:
mx.abort('Error executing \'{}\': {}'.format(' '.join(cmd), str(e)))
mx.logv('{} is not executable. Trying to change permissions...'.format(self.binary))
os.chmod(self.binary, 0o755)
self._run(*args, **kwargs) # retry
else:
not rc or mx.abort(rc if mx.get_opts().verbose else out.data) # pylint: disable=expression-not-assigned
示例6: _ninja_deps
# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import STDOUT [as 別名]
def _ninja_deps(cls): # pylint: disable=no-self-argument
deps = []
try:
subprocess.check_output(['ninja', '--version'], stderr=subprocess.STDOUT)
except OSError:
dep = mx.library('NINJA', False)
if dep:
deps.append(dep.qualifiedName())
Ninja.binary = mx.join(dep.get_path(False), 'ninja')
else:
# necessary until GR-13214 is resolved
mx.warn('Make `ninja` binary available via PATH to build native projects.')
try:
import ninja_syntax # pylint: disable=unused-variable, unused-import
except ImportError:
dep = mx.library('NINJA_SYNTAX')
deps.append(dep.qualifiedName())
module_path = mx.join(dep.get_path(False), 'ninja_syntax-{}'.format(dep.version))
mx.ensure_dir_exists(module_path) # otherwise, import machinery will ignore it
sys.path.append(module_path)
return deps
示例7: get_git_revision
# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import STDOUT [as 別名]
def get_git_revision():
"""When mdp is run from inside a git repository, this function
returns the current revision that git-describe gives us.
If mdp is installed (or git fails for some other reason),
an empty string is returned.
"""
# TODO: Introduce some fallback method that takes the info from a file
revision = ''
try:
# we need to be sure that we call from the mdp dir
mdp_dir = os.path.dirname(mdp.__file__)
# --tags ensures that most revisions have a name even without
# annotated tags
# --dirty=+ appends a plus if the working copy is modified
command = ["git", "describe", "--tags", "--dirty=+"]
proc = Popen(command, stdout=PIPE, stderr=STDOUT, cwd=mdp_dir,
universal_newlines=True)
exit_status = proc.wait()
# only get the revision if command succeded
if exit_status == 0:
revision = proc.stdout.read().strip()
except OSError:
pass
return revision
示例8: run
# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import STDOUT [as 別名]
def run(command, *args):
"""Helper function to run a subprocess in a Python lambda expression.
:type command: string
:param command: external command to run
:type args: strings
:param args: arguments for the external command
:rtype: string
:return: result of running the command
"""
whole = [command]
for arg in args:
g = glob.glob(arg)
if len(g) > 0:
whole.extend(g)
else:
whole.append(arg)
proc = subprocess.Popen(whole, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
returnCode = proc.wait()
output = proc.stdout.read()
if returnCode != 0:
output += "\nsubprocesses failed with exit code {0}".format(returnCode)
return output
示例9: _custodia_cli
# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import STDOUT [as 別名]
def _custodia_cli(self, *args):
env = os.environ.copy()
env['PYTHONWARNINGS'] = 'ignore'
pexec = shlex.split(env.get('CUSTODIAPYTHON', sys.executable))
cli = pexec + [
'-m', 'custodia.cli',
'--verbose'
]
cli.extend(args)
try:
# Python 2.7 doesn't have CalledProcessError.stderr
output = subprocess.check_output(
cli, env=env, stderr=subprocess.STDOUT
)
except subprocess.CalledProcessError as e:
output = e.output
if not isinstance(e.output, six.text_type):
e.output = e.output.decode('utf-8')
raise
else:
if not isinstance(output, six.text_type):
output = output.decode('utf-8')
return output
示例10: startIPy
# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import STDOUT [as 別名]
def startIPy(opts):
global ipy
global respond
global disconnected
global connected
global km
respond = opts["respond"]
connected = opts["connected"]
disconnected = opts["disconnected"]
try:
if os.environ.get('LT_IPYTHON_PATH'):
cmd = os.environ.get('LT_IPYTHON_PATH')
elif os.path.isfile('bin/ipython'):
cmd = 'bin/ipython'
else:
cmd = 'ipython'
ipy = subprocess.Popen([cmd, 'kernel', '--pylab=inline'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=os.environ)
#Start a thread listening to stdout
t = threading.Thread(target=listenIPy)
t.start()
return True
except:
disconnected()
return None
示例11: sign_apk
# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import STDOUT [as 別名]
def sign_apk(filename, keystore, storepass):
"""
Use jarsigner to sign an APK file.
:param filename: APK file on disk to sign (path)
:param keystore: path to keystore
:param storepass: your keystorage passphrase
"""
from subprocess import Popen, PIPE, STDOUT
# TODO use apksigner instead of jarsigner
cmd = Popen([androconf.CONF["BIN_JARSIGNER"], "-sigalg", "MD5withRSA",
"-digestalg", "SHA1", "-storepass", storepass, "-keystore",
keystore, filename, "alias_name"],
stdout=PIPE,
stderr=STDOUT)
stdout, stderr = cmd.communicate()
示例12: __enter__
# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import STDOUT [as 別名]
def __enter__(self):
logging.warning(f'Running s_server: "{self._command_line}"')
args = shlex.split(self._command_line)
try:
self._process = subprocess.Popen(
args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
)
self._server_io_manager = _OpenSslServerIOManager(self._process.stdout, self._process.stdin)
# Block until s_server is ready to accept requests
while not self._server_io_manager.is_server_ready:
time.sleep(1)
if self._process.poll() is not None:
# s_server has terminated early
raise RuntimeError("Could not start s_server")
except Exception as e:
logging.warning(f"Error while starting s_server: {e}")
self._terminate_process()
raise
return self
示例13: test_simple
# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import STDOUT [as 別名]
def test_simple(self):
deps = self.FakeRecipeDeps()
with deps.main_repo.write_recipe('foo') as recipe:
recipe.DEPS = ['recipe_engine/python']
recipe.RunSteps.write('''
api.python.succeeding_step('hey there', "This is some narwhals.")
''')
deps.main_repo.commit('save recipe')
dest = self.tempdir()
output, retcode = deps.main_repo.recipes_py('bundle', '--destination', dest)
self.assertEqual(retcode, 0, 'bundling failed!\noutput:\n'+output)
bat = '.bat' if sys.platform.startswith('win') else ''
proc = subprocess.Popen(
[os.path.join(dest, 'recipes'+bat), 'run', 'foo'],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output, _ = proc.communicate()
self.assertEqual(proc.returncode, 0, 'running failed!\noutput:\n'+output)
self.assertIn('narwhals', output)
示例14: _run_command
# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import STDOUT [as 別名]
def _run_command(command):
p = subprocess.Popen(command,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
return iter(p.stdout.readline, b'')
示例15: _call_security
# 需要導入模塊: import subprocess [as 別名]
# 或者: from subprocess import STDOUT [as 別名]
def _call_security(self, action, service, account, *args):
"""Call ``security`` CLI program that provides access to keychains.
May raise `PasswordNotFound`, `PasswordExists` or `KeychainError`
exceptions (the first two are subclasses of `KeychainError`).
:param action: The ``security`` action to call, e.g.
``add-generic-password``
:type action: ``unicode``
:param service: Name of the service.
:type service: ``unicode``
:param account: name of the account the password is for, e.g.
"Pinboard"
:type account: ``unicode``
:param password: the password to secure
:type password: ``unicode``
:param *args: list of command line arguments to be passed to
``security``
:type *args: `list` or `tuple`
:returns: ``(retcode, output)``. ``retcode`` is an `int`, ``output`` a
``unicode`` string.
:rtype: `tuple` (`int`, ``unicode``)
"""
cmd = ['security', action, '-s', service, '-a', account] + list(args)
p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
stdout, _ = p.communicate()
if p.returncode == 44: # password does not exist
raise PasswordNotFound()
elif p.returncode == 45: # password already exists
raise PasswordExists()
elif p.returncode > 0:
err = KeychainError('Unknown Keychain error : %s' % stdout)
err.retcode = p.returncode
raise err
return stdout.strip().decode('utf-8')