All Samples(50) | Call(47) | Derive(0) | Import(3)
Run command with arguments and return its output as a byte string. If the exit code was non-zero it raises a CalledProcessError. The CalledProcessError object will have the return code in the returncode attribute and output in the output attribute. The arguments are the same as for the Popen constructor. Example: >>> check_output(["ls", "-l", "/dev/null"]) 'crw-rw-rw- 1 root root 1, 3 Oct 18 2007 /dev/null\n' The stdout argument is not allowed as it is used internally. To capture standard error in the result, use stderr=STDOUT. >>> check_output(["/bin/sh", "-c", ... "ls -l non_existent_file ; exit 0"], ... stderr=STDOUT) 'ls: non_existent_file: No such file or directory\n'
def check_output(*popenargs, **kwargs):
r"""Run command with arguments and return its output as a byte string.
If the exit code was non-zero it raises a CalledProcessError. The
CalledProcessError object will have the return code in the returncode
attribute and output in the output attribute.
The arguments are the same as for the Popen constructor. Example:
>>> check_output(["ls", "-l", "/dev/null"])
'crw-rw-rw- 1 root root 1, 3 Oct 18 2007 /dev/null\n'
The stdout argument is not allowed as it is used internally.
To capture standard error in the result, use stderr=STDOUT.
>>> check_output(["/bin/sh", "-c",
... "ls -l non_existent_file ; exit 0"],
... stderr=STDOUT)
'ls: non_existent_file: No such file or directory\n'
"""
if 'stdout' in kwargs:
raise ValueError('stdout argument not allowed, it will be overridden.')
process = Popen(stdout=PIPE, *popenargs, **kwargs)
output, unused_err = process.communicate()
retcode = process.poll()
if retcode:
cmd = kwargs.get("args")
if cmd is None:
cmd = popenargs[0]
raise CalledProcessError(retcode, cmd, output=output)
return output
new_file = ''
for line in file:
if 'jwmn810' in line:
line = subprocess.check_output(['dig', 'Nokia-N810-43-7', '+short'])
linemod = str(line)[2:-3] + '\tjwmn810\n'
line = linemod
new_file = new_file + line
else:
if 'jwmlt1' in line:
line = subprocess.check_output(['dig', 'jwmlt1', '+short'])
new_file = new_file + line
else:
if 'jwmlt2' in line:
line = subprocess.check_output(['dig', 'jwmlt2', '+short'])
linemod = str(line)[2:-3] + '\tjwmlt2\n'
line = linemod
new_file = new_file + line
else:
if 'jwmdt1' in line:
line = subprocess.check_output(['dig', 'jwmdt1', '+short'])
src/s/m/smush.py-HEAD/optimiser/optimiser.py smush.py(Download)
test_command = 'identify -format %%m "%s"' % input
args = shlex.split(test_command)
try:
output = subprocess.check_output(args)
except OSError:
print "Error executing command %s. Error was %s" % (test_command, OSError)
sys.exit(1)
src/s/m/smush.py-HEAD/smush.py smush.py(Download)
test_command = 'identify -format %%m "%s"' % input
args = shlex.split(test_command)
try:
output = subprocess.check_output(args)
except OSError:
print "Error executing command %s. Error was %s" % (test_command, OSError)
sys.exit(1)
src/m/p/mplayer-resume-HEAD/mplayer-resume.py mplayer-resume(Download)
#!/usr/bin/python3 #TODO: refactor import sys from os.path import expanduser import pickle from subprocess import check_output
# compose mplayer commad cmd = [mplayer, '-ss', time_to_resume, file_name] + flags # wait until it finish mplayer_output = str(check_output(cmd)) # get new resume time time_to_resume = parse_mplayer_output(mplayer_output)
src/i/r/ironruby-HEAD/External.LCA_RESTRICTED/Languages/IronPython/27/Lib/test/test_subprocess.py ironruby(Download)
def test_check_output(self):
# check_output() function with zero return code
output = subprocess.check_output(
[sys.executable, "-c", "print 'BDFL'"])
self.assertIn('BDFL', output)
def test_check_output_nonzero(self):
# check_call() function with non-zero return code
with self.assertRaises(subprocess.CalledProcessError) as c:
subprocess.check_output(
[sys.executable, "-c", "import sys; sys.exit(5)"])
def test_check_output_stderr(self):
# check_output() function stderr redirected to stdout
output = subprocess.check_output(
[sys.executable, "-c", "import sys; sys.stderr.write('BDFL')"],
stderr=subprocess.STDOUT)
self.assertIn('BDFL', output)
def test_check_output_stdout_arg(self):
# check_output() function stderr redirected to stdout
with self.assertRaises(ValueError) as c:
output = subprocess.check_output(
[sys.executable, "-c", "print 'will not be run'"],
src/i/r/ironruby-HEAD/External.LCA_RESTRICTED/Languages/CPython/27/Lib/test/test_subprocess.py ironruby(Download)
def test_check_output(self):
# check_output() function with zero return code
output = subprocess.check_output(
[sys.executable, "-c", "print 'BDFL'"])
self.assertIn('BDFL', output)
def test_check_output_nonzero(self):
# check_call() function with non-zero return code
with self.assertRaises(subprocess.CalledProcessError) as c:
subprocess.check_output(
[sys.executable, "-c", "import sys; sys.exit(5)"])
def test_check_output_stderr(self):
# check_output() function stderr redirected to stdout
output = subprocess.check_output(
[sys.executable, "-c", "import sys; sys.stderr.write('BDFL')"],
stderr=subprocess.STDOUT)
self.assertIn('BDFL', output)
def test_check_output_stdout_arg(self):
# check_output() function stderr redirected to stdout
with self.assertRaises(ValueError) as c:
output = subprocess.check_output(
[sys.executable, "-c", "print 'will not be run'"],
src/p/y/pyvm-HEAD/projects/python_in_a_can/trunk/win32/python-2.7/Lib/test/test_subprocess.py pyvm(Download)
def test_check_output(self):
# check_output() function with zero return code
output = subprocess.check_output(
[sys.executable, "-c", "print 'BDFL'"])
self.assertIn('BDFL', output)
def test_check_output_nonzero(self):
# check_call() function with non-zero return code
with self.assertRaises(subprocess.CalledProcessError) as c:
subprocess.check_output(
[sys.executable, "-c", "import sys; sys.exit(5)"])
def test_check_output_stderr(self):
# check_output() function stderr redirected to stdout
output = subprocess.check_output(
[sys.executable, "-c", "import sys; sys.stderr.write('BDFL')"],
stderr=subprocess.STDOUT)
self.assertIn('BDFL', output)
def test_check_output_stdout_arg(self):
# check_output() function stderr redirected to stdout
with self.assertRaises(ValueError) as c:
output = subprocess.check_output(
[sys.executable, "-c", "print 'will not be run'"],
src/s/t/stackless-HEAD/Lib/test/test_subprocess.py stackless(Download)
def test_check_output(self):
# check_output() function with zero return code
output = subprocess.check_output(
[sys.executable, "-c", "print 'BDFL'"])
self.assertIn('BDFL', output)
def test_check_output_nonzero(self):
# check_call() function with non-zero return code
with self.assertRaises(subprocess.CalledProcessError) as c:
subprocess.check_output(
[sys.executable, "-c", "import sys; sys.exit(5)"])
def test_check_output_stderr(self):
# check_output() function stderr redirected to stdout
output = subprocess.check_output(
[sys.executable, "-c", "import sys; sys.stderr.write('BDFL')"],
stderr=subprocess.STDOUT)
self.assertIn('BDFL', output)
def test_check_output_stdout_arg(self):
# check_output() function stderr redirected to stdout
with self.assertRaises(ValueError) as c:
output = subprocess.check_output(
[sys.executable, "-c", "print 'will not be run'"],
src/j/y/jython-HEAD/sandbox/wierzbicki/test27/CPythonLib/test/test_subprocess.py jython(Download)
def test_check_output(self):
# check_output() function with zero return code
output = subprocess.check_output(
[sys.executable, "-c", "print 'BDFL'"])
self.assertTrue('BDFL' in output)
def test_check_output_nonzero(self):
# check_call() function with non-zero return code
try:
subprocess.check_output(
[sys.executable, "-c", "import sys; sys.exit(5)"])
def test_check_output_stderr(self):
# check_output() function stderr redirected to stdout
output = subprocess.check_output(
[sys.executable, "-c", "import sys; sys.stderr.write('BDFL')"],
stderr=subprocess.STDOUT)
self.assertTrue('BDFL' in output)
def test_check_output_stdout_arg(self):
# check_output() function stderr redirected to stdout
try:
output = subprocess.check_output(
[sys.executable, "-c", "print 'will not be run'"],
src/p/y/pypy3-HEAD/lib-python/3.1.2/test/test_subprocess.py pypy3(Download)
def test_check_output(self):
# check_output() function with zero return code
output = subprocess.check_output(
[sys.executable, "-c", "print('BDFL')"])
self.assertTrue(b'BDFL' in output)
def test_check_output_nonzero(self):
# check_call() function with non-zero return code
try:
subprocess.check_output(
[sys.executable, "-c", "import sys; sys.exit(5)"])
def test_check_output_stderr(self):
# check_output() function stderr redirected to stdout
output = subprocess.check_output(
[sys.executable, "-c", "import sys; sys.stderr.write('BDFL')"],
stderr=subprocess.STDOUT)
self.assertTrue(b'BDFL' in output)
def test_check_output_stdout_arg(self):
# check_output() function stderr redirected to stdout
try:
output = subprocess.check_output(
[sys.executable, "-c", "print('will not be run')"],
1 | 2 Next