本文整理汇总了Python中subprocess2.communicate函数的典型用法代码示例。如果您正苦于以下问题:Python communicate函数的具体用法?Python communicate怎么用?Python communicate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了communicate函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_timeout
def test_timeout(self):
# It'd be better to not discard stdout.
out, returncode = subprocess2.communicate(
self.exe + ['--sleep', '--stdout'],
timeout=0.01,
stdout=subprocess2.PIPE)
self.assertEquals(subprocess2.TIMED_OUT, returncode)
self.assertEquals(['', None], out)
示例2: test_stdout_void
def test_stdout_void(self):
(out, err), code = subprocess2.communicate(
self.exe + ['--stdout', '--stderr'],
stdout=subprocess2.VOID,
stderr=subprocess2.PIPE)
self.assertEquals(None, out)
self.assertEquals('a\nbb\nccc\n', err)
self.assertEquals(0, code)
示例3: test_communicate_defaults
def test_communicate_defaults(self):
results = self._fake_Popen()
self.assertEquals(
((None, None), -8), subprocess2.communicate(['foo'], a=True))
expected = {
'args': ['foo'],
'a': True,
}
self.assertEquals(expected, results)
示例4: test_stderr_void
def test_stderr_void(self):
(out, err), code = subprocess2.communicate(
self.exe + ['--stdout', '--stderr'],
universal_newlines=True,
stdout=subprocess2.PIPE,
stderr=subprocess2.VOID)
self.assertEquals('A\nBB\nCCC\n', out)
self.assertEquals(None, err)
self.assertEquals(0, code)
示例5: fn
def fn(c, e, un):
res = subprocess2.communicate(
e + ['--stdout', '--read'],
stdin=VOID,
stdout=PIPE,
timeout=10,
universal_newlines=un,
shell=False)
self._check_res(res, c('A\nBB\nCCC\n'), None, 0)
示例6: test_tee_large_stdin
def test_tee_large_stdin(self):
stdout = []
# Write 128kb.
stdin = '0123456789abcdef' * (8*1024)
res = subprocess2.communicate(
self.exe + ['--large', '--read'], stdin=stdin, stdout=stdout.append)
self.assertEquals(128*1024, len(''.join(stdout)))
# Windows return code is > 8 bits.
returncode = len(stdin) if sys.platform == 'win32' else 0
self._check_res(res, None, None, returncode)
示例7: CallCommand
def CallCommand(cmd_data):
# multiprocessing needs a top level function with a single argument.
cmd_data.kwargs['stdout'] = subprocess.PIPE
cmd_data.kwargs['stderr'] = subprocess.STDOUT
try:
(out, _), code = subprocess.communicate(cmd_data.cmd, **cmd_data.kwargs)
if code != 0:
return cmd_data.message('%s failed\n%s' % (cmd_data.name, out))
except OSError as e:
return cmd_data.message(
'%s exec failure\n %s' % (cmd_data.name, e))
示例8: check_call
def check_call(self, *args):
((out, err), code) = subprocess2.communicate(
(sys.executable, self.path) + args,
stdout=subprocess2.PIPE,
stderr=subprocess2.PIPE,
env=self.get_sub_env(),
timeout=self.timeout,
)
# Parse output.
status_code_match = re.search("status=([0-9]+)", err)
if status_code_match:
return (int(status_code_match.group(1)), out, err)
if "You are attempting to access protected data with " "no configured credentials." in err:
return (403, out, err)
if "No such object" in err:
return (404, out, err)
return (code, out, err)
示例9: check_call
def check_call(self, *args):
cmd = [sys.executable, self.path, '--force-version', self.version]
cmd.extend(args)
((out, err), code) = subprocess2.communicate(
cmd,
stdout=subprocess2.PIPE,
stderr=subprocess2.PIPE,
env=self.get_sub_env(),
timeout=self.timeout)
# Parse output.
status_code_match = re.search('status=([0-9]+)', err)
if status_code_match:
return (int(status_code_match.group(1)), out, err)
if ('You are attempting to access protected data with '
'no configured credentials.' in err):
return (403, out, err)
if 'matched no objects' in err:
return (404, out, err)
return (code, out, err)
示例10: check_call
def check_call(self, *args):
env = os.environ.copy()
if self.boto_path:
env['AWS_CREDENTIAL_FILE'] = self.boto_path
((out, err), code) = subprocess2.communicate(
(sys.executable, self.path) + args,
stdout=subprocess2.PIPE,
stderr=subprocess2.PIPE,
env=env,
timeout=self.timeout)
# Parse output.
status_code_match = re.search('status=([0-9]+)', err)
if status_code_match:
return (int(status_code_match.group(1)), out, err)
if ('You are attempting to access protected data with '
'no configured credentials.' in err):
return (403, out, err)
if 'No such object' in err:
return (404, out, err)
return (code, out, err)