本文整理汇总了Python中subprocess.DEVNULL属性的典型用法代码示例。如果您正苦于以下问题:Python subprocess.DEVNULL属性的具体用法?Python subprocess.DEVNULL怎么用?Python subprocess.DEVNULL使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类subprocess
的用法示例。
在下文中一共展示了subprocess.DEVNULL属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import subprocess [as 别名]
# 或者: from subprocess import DEVNULL [as 别名]
def __init__(self, board, commands, options, silence_stderr=False):
commands = commands[0] if len(commands) == 1 else commands
self.go_commands = options.get("go_commands", {})
self.engine = chess.uci.popen_engine(commands, stderr = subprocess.DEVNULL if silence_stderr else None)
self.engine.uci()
if options:
self.engine.setoption(options)
self.engine.setoption({
"UCI_Variant": type(board).uci_variant,
"UCI_Chess960": board.chess960
})
self.engine.position(board)
info_handler = chess.uci.InfoHandler()
self.engine.info_handlers.append(info_handler)
示例2: open_media
# 需要导入模块: import subprocess [as 别名]
# 或者: from subprocess import DEVNULL [as 别名]
def open_media(scr, epub, src):
sfx = os.path.splitext(src)[1]
fd, path = tempfile.mkstemp(suffix=sfx)
try:
with os.fdopen(fd, "wb") as tmp:
tmp.write(epub.file.read(src))
# run(VWR +" "+ path, shell=True)
subprocess.call(
VWR + [path],
# shell=True,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL
)
k = scr.getch()
finally:
os.remove(path)
return k
示例3: run_and_summarize
# 需要导入模块: import subprocess [as 别名]
# 或者: from subprocess import DEVNULL [as 别名]
def run_and_summarize(tap, config, state=None, debug=False):
cmd = [tap, '--config', config]
if state:
cmd += ['--state', state]
print('Running command {}'.format(' '.join(cmd)))
stderr = None if debug else subprocess.DEVNULL
tap = Popen(cmd,
stdout=subprocess.PIPE,
stderr=stderr,
bufsize=1,
universal_newlines=True)
summarizer = StdoutReader(tap)
summarizer.start()
returncode = tap.wait()
if returncode != 0:
print('ERROR: tap exited with status {}'.format(returncode))
exit(1)
return summarizer.summary
示例4: get_version
# 需要导入模块: import subprocess [as 别名]
# 或者: from subprocess import DEVNULL [as 别名]
def get_version():
"""Obtain version information from git if available otherwise use
the internal version number
"""
def internal_version():
return '.'.join(map(str, __version_info__[:3])) + ''.join(__version_info__[3:])
try:
p = Popen(["git", "describe", "--tags"], stdout=PIPE, stderr=DEVNULL)
except OSError:
return internal_version()
stdout, stderr = p.communicate()
if p.returncode:
return internal_version()
else:
# Both py2 and py3 return bytes here
return stdout.decode(USR_ENCODING).strip()
示例5: get_latest_version
# 需要导入模块: import subprocess [as 别名]
# 或者: from subprocess import DEVNULL [as 别名]
def get_latest_version(self, _request: WSGIRequest) -> HttpResponse:
"""Looks up the newest version number from PyPi and returns it."""
try:
subprocess.run(
"pip3 install raveberry==nonexistingversion".split(),
stdout=subprocess.DEVNULL,
stderr=subprocess.PIPE,
universal_newlines=True,
check=True,
)
except subprocess.CalledProcessError as e:
# parse the newest verson from pip output
for line in e.stderr.splitlines():
if "from versions" in line:
versions = [re.sub(r"[^0-9.]", "", token) for token in line.split()]
versions = [version for version in versions if version]
latest_version = versions[-1]
return HttpResponse(latest_version)
return HttpResponseBadRequest("Could not determine latest version.")
示例6: set_output_device
# 需要导入模块: import subprocess [as 别名]
# 或者: from subprocess import DEVNULL [as 别名]
def set_output_device(self, request: WSGIRequest) -> HttpResponse:
"""Sets the given device as default output device."""
device = request.POST.get("device")
if not device:
return HttpResponseBadRequest("No device selected")
try:
subprocess.run(
["pactl", "set-default-sink", device],
stdout=subprocess.DEVNULL,
stderr=subprocess.PIPE,
env={"PULSE_SERVER": "127.0.0.1"},
check=True,
)
except subprocess.CalledProcessError as e:
return HttpResponseBadRequest(e.stderr)
# restart mopidy to apply audio device change
subprocess.call(["sudo", "/usr/local/sbin/raveberry/restart_mopidy"])
return HttpResponse(
f"Set default output. Restarting the current song might be necessary."
)
示例7: _get_asciidoc_cmd
# 需要导入模块: import subprocess [as 别名]
# 或者: from subprocess import DEVNULL [as 别名]
def _get_asciidoc_cmd(self) -> List[str]:
"""Try to find out what commandline to use to invoke asciidoc."""
if self._asciidoc is not None:
return self._asciidoc
for executable in ['asciidoc', 'asciidoc.py']:
try:
subprocess.run([executable, '--version'],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
check=True)
except OSError:
pass
else:
return [executable]
raise FileNotFoundError
示例8: start_or_restart_ffmpeg
# 需要导入模块: import subprocess [as 别名]
# 或者: from subprocess import DEVNULL [as 别名]
def start_or_restart_ffmpeg(ffmpeg_cmd, frame_size, ffmpeg_process=None):
if not ffmpeg_process is None:
print("Terminating the existing ffmpeg process...")
ffmpeg_process.terminate()
try:
print("Waiting for ffmpeg to exit gracefully...")
ffmpeg_process.communicate(timeout=30)
except sp.TimeoutExpired:
print("FFmpeg didnt exit. Force killing...")
ffmpeg_process.kill()
ffmpeg_process.communicate()
ffmpeg_process = None
print("Creating ffmpeg process...")
print(" ".join(ffmpeg_cmd))
process = sp.Popen(ffmpeg_cmd, stdout = sp.PIPE, stdin = sp.DEVNULL, bufsize=frame_size*10, start_new_session=True)
return process
示例9: __init__
# 需要导入模块: import subprocess [as 别名]
# 或者: from subprocess import DEVNULL [as 别名]
def __init__(self, source, *, executable='ffmpeg', pipe=False, stderr=None, before_options=None, options=None):
args = []
subprocess_kwargs = {'stdin': source if pipe else subprocess.DEVNULL, 'stderr': stderr}
if isinstance(before_options, str):
args.extend(shlex.split(before_options))
args.append('-i')
args.append('-' if pipe else source)
args.extend(('-f', 's16le', '-ar', '48000', '-ac', '2', '-loglevel', 'warning'))
if isinstance(options, str):
args.extend(shlex.split(options))
args.append('pipe:1')
super().__init__(source, executable=executable, args=args, **subprocess_kwargs)
示例10: cleanup_docker_environment_before_test_execution
# 需要导入模块: import subprocess [as 别名]
# 或者: from subprocess import DEVNULL [as 别名]
def cleanup_docker_environment_before_test_execution():
"""
perform a bunch of system cleanup operations, like kill any instances that might be
hanging around incorrectly from a previous run, sync the disk, and clear swap.
Ideally we would also drop the page cache, but as docker isn't running in privileged
mode there is no way for us to do this.
"""
# attempt to wack all existing running Cassandra processes forcefully to get us into a clean state
p_kill = subprocess.Popen('ps aux | grep -ie CassandraDaemon | grep java | grep -v grep | awk \'{print $2}\' | xargs kill -9',
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, shell=True)
p_kill.wait(timeout=10)
# explicitly call "sync" to flush everything that might be pending from a previous test
# so tests are less likely to hit a very slow fsync during the test by starting from a 'known' state
# note: to mitigate this further the docker image is mounting /tmp as a volume, which gives
# us an ext4 mount which should talk directly to the underlying device on the host, skipping
# the aufs pain that we get with anything else running in the docker image. Originally,
# I had a timeout of 120 seconds (2 minutes), 300 seconds (5 minutes) but sync was still occasionally timing out.
p_sync = subprocess.Popen('sudo /bin/sync', shell=True)
p_sync.wait(timeout=600)
# turn swap off and back on to make sure it's fully cleared if anything happened to swap
# from a previous test run
p_swap = subprocess.Popen('sudo /sbin/swapoff -a && sudo /sbin/swapon -a', shell=True)
p_swap.wait(timeout=60)
示例11: run
# 需要导入模块: import subprocess [as 别名]
# 或者: from subprocess import DEVNULL [as 别名]
def run(self):
"""Runs plantUML"""
srcFile = self.__fName[:-3] + 'txt'
try:
# Run plantUML
saveToFile(srcFile, self.__source)
retCode = subprocess.call(['java', '-jar', JAR_PATH,
'-charset', 'utf-8', '-nometadata',
srcFile],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL)
self.safeUnlink(srcFile)
if retCode == 0:
self.sigFinishedOK.emit(self.__md5, self.__uuid, self.__fName)
else:
self.sigFinishedError.emit(self.__md5, self.__fName)
except Exception as exc:
logging.error('Cannot render a plantUML diagram: %s', str(exc))
self.safeUnlink(srcFile)
self.sigFinishedError.emit(self.__md5, self.__fName)
示例12: _run
# 需要导入模块: import subprocess [as 别名]
# 或者: from subprocess import DEVNULL [as 别名]
def _run(args, stdout=None, stderr=None):
from collections import namedtuple
result = namedtuple('CompletedProcess', 'stdout stderr returncode')
devnull = None
if subprocess.DEVNULL in (stdout, stderr):
devnull = open(os.devnull, 'r+')
if stdout == subprocess.DEVNULL:
stdout = devnull
if stderr == subprocess.DEVNULL:
stderr = devnull
proc = subprocess.Popen(args, stdout=stdout, stderr=stderr)
stdout, stderr = proc.communicate()
res = result(stdout, stderr, proc.returncode)
if devnull is not None:
devnull.close()
return res
示例13: check_output
# 需要导入模块: import subprocess [as 别名]
# 或者: from subprocess import DEVNULL [as 别名]
def check_output(*args, **kwargs):
"""
### check_output
Returns stdin output from subprocess module
"""
# import libs
import subprocess as sp
from subprocess import DEVNULL
# execute command in subprocess
process = sp.Popen(stdout=sp.PIPE, stderr=DEVNULL, *args, **kwargs)
output, unused_err = process.communicate()
retcode = process.poll()
# if error occurred raise error
if retcode:
cmd = kwargs.get("args")
if cmd is None:
cmd = args[0]
error = sp.CalledProcessError(retcode, cmd)
error.output = output
raise error
return output
示例14: write_table_in_format
# 需要导入模块: import subprocess [as 别名]
# 或者: from subprocess import DEVNULL [as 别名]
def write_table_in_format(template_format, outfile, options, **kwargs):
callback = {"csv": write_csv_table, "html": htmltable.write_html_table}[
template_format
]
if outfile:
# Force HTML file to be UTF-8 regardless of system encoding because it actually
# declares itself to be UTF-8 in a meta tag.
encoding = "utf-8" if template_format == "html" else None
with open(outfile, "w", encoding=encoding) as out:
callback(out, options=options, **kwargs)
if options.show_table and template_format == "html":
try:
subprocess.Popen(
["xdg-open", outfile],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
except OSError:
pass
else:
callback(sys.stdout, options=options, **kwargs)
示例15: disassemble_file
# 需要导入模块: import subprocess [as 别名]
# 或者: from subprocess import DEVNULL [as 别名]
def disassemble_file(bin_path, asm_path):
command = [
r"C:\devkitPro\devkitPPC\bin\powerpc-eabi-objdump.exe",
"--disassemble-zeroes",
"-m", "powerpc",
"-D",
"-b", "binary",
"-EB",
bin_path
]
print(" ".join(command))
print()
with open(asm_path, "wb") as f:
result = call(command, stdout=f, stdin=DEVNULL, stderr=DEVNULL)
if result != 0:
raise Exception("Disassembler call failed")