本文整理汇总了Python中cpopen.CPopen.wait方法的典型用法代码示例。如果您正苦于以下问题:Python CPopen.wait方法的具体用法?Python CPopen.wait怎么用?Python CPopen.wait使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cpopen.CPopen
的用法示例。
在下文中一共展示了CPopen.wait方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testUserFileWithRedirect
# 需要导入模块: from cpopen import CPopen [as 别名]
# 或者: from cpopen.CPopen import wait [as 别名]
def testUserFileWithRedirect(self):
data = "it works!"
with tempfile.TemporaryFile() as f:
p = CPopen(["echo", "-n", data], stdout=f, stderr=f)
p.wait()
f.seek(0)
self.assertEqual(data, f.read())
示例2: testCwd
# 需要导入模块: from cpopen import CPopen [as 别名]
# 或者: from cpopen.CPopen import wait [as 别名]
def testCwd(self):
cwd = "/proc"
p = CPopen(["python", "-c", "import os; print os.getcwd()"], cwd=cwd)
p.wait()
self.assertTrue(p.returncode == 0,
"Process failed: %s" % os.strerror(p.returncode))
self.assertEquals(p.stdout.read().strip(), cwd)
示例3: testNoStreams
# 需要导入模块: from cpopen import CPopen [as 别名]
# 或者: from cpopen.CPopen import wait [as 别名]
def testNoStreams(self):
p = CPopen(['true'], stdin=None, stdout=None, stderr=None)
self.assertEqual(p.stdin, None)
self.assertEqual(p.stdout, None)
self.assertEqual(p.stderr, None)
p.wait()
self.assertEquals(p.returncode, 0)
示例4: _subTest
# 需要导入模块: from cpopen import CPopen [as 别名]
# 或者: from cpopen.CPopen import wait [as 别名]
def _subTest(self, name, params, *args, **kwargs):
p = CPopen(["python", EXT_HELPER, name] + params,
*args, **kwargs)
p.wait()
self.assertTrue(p.returncode == 0,
"Process failed: %s" % os.strerror(p.returncode))
self.assertEquals(p.stdout.read().strip(), "True")
示例5: testEcho
# 需要导入模块: from cpopen import CPopen [as 别名]
# 或者: from cpopen.CPopen import wait [as 别名]
def testEcho(self):
data = "Hello"
p = CPopen([EXT_ECHO, "-n", data])
p.wait()
self.assertTrue(p.returncode == 0,
"Process failed: %s" % os.strerror(p.returncode))
self.assertEquals(p.stdout.read(), data)
示例6: testBrokenPipe
# 需要导入模块: from cpopen import CPopen [as 别名]
# 或者: from cpopen.CPopen import wait [as 别名]
def testBrokenPipe(self):
p = CPopen(["sleep", "1"])
try:
p.send_signal(signal.SIGPIPE)
finally:
p.kill()
p.wait()
self.assertEqual(p.returncode, -signal.SIGKILL)
示例7: testCloseOnExecStderr
# 需要导入模块: from cpopen import CPopen [as 别名]
# 或者: from cpopen.CPopen import wait [as 别名]
def testCloseOnExecStderr(self):
# Unset close-on-exec on stderr fd
with tempfile.NamedTemporaryFile() as f:
set_close_on_exec(f.fileno())
p = CPopen(["sh", "-c", "echo -n data >&2"], stderr=f.fileno())
p.wait()
f.seek(0)
self.assertEqual(f.read(), "data")
示例8: testCat
# 需要导入模块: from cpopen import CPopen [as 别名]
# 或者: from cpopen.CPopen import wait [as 别名]
def testCat(self):
path = "/etc/passwd"
p = CPopen(["cat", path])
p.wait()
self.assertTrue(p.returncode == 0,
"Process failed: %s" % os.strerror(p.returncode))
with open(path, "r") as f:
self.assertEquals(p.stdout.read(), f.read())
示例9: testCloseFDs
# 需要导入模块: from cpopen import CPopen [as 别名]
# 或者: from cpopen.CPopen import wait [as 别名]
def testCloseFDs(self):
with open("/dev/zero") as f:
p = CPopen(["sleep", "1"], close_fds=True)
try:
child_fds = set(os.listdir("/proc/%s/fd" % p.pid))
finally:
p.kill()
p.wait()
self.assertEqual(child_fds, set(["0", "1", "2"]))
示例10: testUnicodeArg
# 需要导入模块: from cpopen import CPopen [as 别名]
# 或者: from cpopen.CPopen import wait [as 别名]
def testUnicodeArg(self):
data = u'hello'
cmd = [EXT_ECHO, "-n", data]
p = CPopen(cmd)
p.wait()
p2 = subprocess.Popen(cmd, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p2.wait()
self.assertEquals(p.stdout.read(), p2.stdout.read())
示例11: testBrokenPipeSIGPIPERestored
# 需要导入模块: from cpopen import CPopen [as 别名]
# 或者: from cpopen.CPopen import wait [as 别名]
def testBrokenPipeSIGPIPERestored(self):
if not cpopen.SUPPORTS_RESTORE_SIGPIPE:
raise SkipTest("subprocess module does not support restore_sigpipe")
p = CPopen(["sleep", "1"], restore_sigpipe=True)
try:
p.send_signal(signal.SIGPIPE)
finally:
p.kill()
p.wait()
self.assertEqual(p.returncode, -signal.SIGPIPE)
示例12: testPipeline
# 需要导入模块: from cpopen import CPopen [as 别名]
# 或者: from cpopen.CPopen import wait [as 别名]
def testPipeline(self):
# echo -n 'it works!' | cat
data = "it works!"
p2 = CPopen(["cat"], stdin=PIPE, stdout=PIPE)
try:
p1 = CPopen(["echo", "-n", data], stdin=PIPE, stdout=p2.stdin)
p1.wait()
finally:
out, err = p2.communicate()
self.assertEqual(data, out)
示例13: testStdin
# 需要导入模块: from cpopen import CPopen [as 别名]
# 或者: from cpopen.CPopen import wait [as 别名]
def testStdin(self):
data = "Hello World"
p = CPopen(["cat"])
p.stdin.write(data)
p.stdin.flush()
p.stdin.close()
p.wait()
self.assertTrue(p.returncode == 0,
"Process failed: %s" % os.strerror(p.returncode))
self.assertEquals(p.stdout.read(), data)
示例14: testNoCloseFds
# 需要导入模块: from cpopen import CPopen [as 别名]
# 或者: from cpopen.CPopen import wait [as 别名]
def testNoCloseFds(self):
with open("/dev/zero") as f:
p = CPopen(["sleep", "1"], close_fds=False)
try:
child_fds = set(os.listdir("/proc/%s/fd" % p.pid))
finally:
p.kill()
p.wait()
# We cannot know which fds will be inherited in the child since the
# test framework may open some fds.
self.assertTrue(str(f.fileno()) in child_fds)
示例15: testInheritParentFdsCloseFds
# 需要导入模块: from cpopen import CPopen [as 别名]
# 或者: from cpopen.CPopen import wait [as 别名]
def testInheritParentFdsCloseFds(self):
# From Python docs: If close_fds is true, all file descriptors except
# 0, 1 and 2 will be closed before the child process is executed.
with open("/dev/zero") as f:
p = CPopen(["sleep", "1"], stdin=None, stdout=None, stderr=None,
close_fds=True)
try:
child_fds = set(os.listdir("/proc/%s/fd" % p.pid))
finally:
p.kill()
p.wait()
self.assertEqual(child_fds, set(["0", "1", "2"]))