本文整理汇总了Python中pysh.run函数的典型用法代码示例。如果您正苦于以下问题:Python run函数的具体用法?Python run怎么用?Python run使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了run函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: testPyCmdInVar
def testPyCmdInVar(self):
class Tmp(object):
def process(self, args, input):
return ['tmp', 19]
tmp = Tmp()
pysh.run('$tmp > out.txt', globals(), locals())
self.assertEquals('tmp\n19\n', file('out.txt').read())
开发者ID:yunabe,项目名称:codelab,代码行数:7,代码来源:pysh_test.py
示例2: testOrNotPyCmd
def testOrNotPyCmd(self):
class Tmp(object):
def process(self, args, input):
raise Exception('Error!')
tmp = Tmp()
pysh.run('$tmp > out.txt || echo foo >> out.txt', globals(), locals())
self.assertEquals('foo\n', file('out.txt').read())
开发者ID:yunabe,项目名称:codelab,代码行数:7,代码来源:pysh_test.py
示例3: testNumberedRedirect
def testNumberedRedirect(self):
pysh.run('python -c "import sys;'
'print >> sys.stderr, \'error\';print \'out\'"'
'> stdout.txt 2> stderr.txt',
globals(), locals())
self.assertEquals('error\n', file('stderr.txt').read())
self.assertEquals('out\n', file('stdout.txt').read())
开发者ID:yunabe,项目名称:codelab,代码行数:7,代码来源:pysh_test.py
示例4: testOrPyCmd
def testOrPyCmd(self):
class Tmp(object):
def process(self, args, input):
return ['tmp']
tmp = Tmp()
pysh.run('$tmp > out.txt || echo foo >> out.txt', globals(), locals())
self.assertEquals('tmp\n', file('out.txt').read())
开发者ID:yunabe,项目名称:codelab,代码行数:7,代码来源:pysh_test.py
示例5: testReadCvsCmd
def testReadCvsCmd(self):
pysh.run('echo \'a,b,"c,"\' > in.txt', globals(), locals())
pysh.run('echo \'e,"f","""g"""\' >> in.txt', globals(), locals())
pysh.run('cat in.txt | readcsv |'
'map ${lambda row: row[2]} > out.txt',
globals(), locals())
self.assertEquals('c,\n"g"\n', file('out.txt').read())
开发者ID:yunabe,项目名称:codelab,代码行数:7,代码来源:pysh_test.py
示例6: testReduceCmd
def testReduceCmd(self):
pysh.run('echo "foo\\nbar" | reduce ${lambda x, y: x + y} |'
'cat > out.txt', globals(), locals())
self.assertEquals('foobar\n', file('out.txt').read())
开发者ID:yunabe,项目名称:codelab,代码行数:4,代码来源:pysh_test.py
示例7: testBuiltinVar
def testBuiltinVar(self):
map_str = str(map)
pysh.run('echo $map > out.txt', globals(), locals())
self.assertEquals(map_str + '\n', file('out.txt').read())
开发者ID:yunabe,项目名称:codelab,代码行数:4,代码来源:pysh_test.py
示例8: testChangeDir
def testChangeDir(self):
rc = pysh.run('cd /dev', globals(), locals())
self.assertEquals('/dev', os.getcwd())
开发者ID:yunabe,项目名称:codelab,代码行数:3,代码来源:pysh_test.py
示例9: testSemiColon
def testSemiColon(self):
rc = pysh.run('echo foo >> out.txt; echo bar >> out.txt',
globals(), locals())
self.assertEquals('foo\nbar\n', file('out.txt').read())
开发者ID:yunabe,项目名称:codelab,代码行数:4,代码来源:pysh_test.py
示例10: testListComprehension
def testListComprehension(self):
pysh.run('send ${[x * x for x in xrange(3)]} > out.txt',
globals(), locals())
self.assertEquals('0\n1\n4\n', file('out.txt').read())
开发者ID:yunabe,项目名称:codelab,代码行数:4,代码来源:pysh_test.py
示例11: testAndOr
def testAndOr(self):
pysh.run('(python -c "import sys;sys.exit(1)" >> out.txt && echo bar) || '
'echo baz >> out.txt)', globals(), locals())
self.assertEquals('baz\n', file('out.txt').read())
开发者ID:yunabe,项目名称:codelab,代码行数:4,代码来源:pysh_test.py
示例12: testPyCmdSequence
def testPyCmdSequence(self):
pysh.run('echo "foo" | pycmd bar | pycmd baz | cat > out.txt',
globals(), locals())
self.assertEquals('pycmd\nbaz\npycmd\nbar\nfoo\n', file('out.txt').read())
开发者ID:yunabe,项目名称:codelab,代码行数:4,代码来源:pysh_test.py
示例13: testPyCmdRedirect
def testPyCmdRedirect(self):
pysh.run('echo "foo" | pycmd a b c > out.txt',
globals(), locals())
self.assertEquals('pycmd\na\nb\nc\nfoo\n', file('out.txt').read())
开发者ID:yunabe,项目名称:codelab,代码行数:4,代码来源:pysh_test.py
示例14: testPyCmd
def testPyCmd(self):
pysh.run('echo "foo\\nbar" | pycmd a b c | cat > out.txt',
globals(), locals())
self.assertEquals('pycmd\na\nb\nc\nfoo\nbar\n', file('out.txt').read())
开发者ID:yunabe,项目名称:codelab,代码行数:4,代码来源:pysh_test.py
示例15: testListArgs
def testListArgs(self):
args = ['a', 'b', 10, {1: 3}]
pysh.run('python -c "import sys;print sys.argv" '
'$args > out.txt', globals(), locals())
argv = eval(file('out.txt').read())
self.assertEquals(['-c', 'a', 'b', '10', '{1: 3}'], argv)
开发者ID:yunabe,项目名称:codelab,代码行数:6,代码来源:pysh_test.py
示例16: testStringArgs
def testStringArgs(self):
pysh.run('python -c "import sys;print sys.argv" '
'"a b" \'c d\' e f > out.txt', globals(), locals())
argv = eval(file('out.txt').read())
self.assertEquals(['-c', 'a b', 'c d', 'e', 'f'], argv)
开发者ID:yunabe,项目名称:codelab,代码行数:5,代码来源:pysh_test.py
示例17: testEnvVar
def testEnvVar(self):
os.environ['YUNABE_PYSH_TEST_VAR'] = 'foobarbaz'
pysh.run('echo $YUNABE_PYSH_TEST_VAR > out.txt', globals(), locals())
self.assertEquals('foobarbaz\n', file('out.txt').read())
开发者ID:yunabe,项目名称:codelab,代码行数:4,代码来源:pysh_test.py
示例18: testOr
def testOr(self):
pysh.run('echo hoge >> out.txt || echo piyo >> out.txt',
globals(), locals())
self.assertEquals('hoge\n', file('out.txt').read())
开发者ID:yunabe,项目名称:codelab,代码行数:4,代码来源:pysh_test.py
示例19: testOrAnd
def testOrAnd(self):
pysh.run('(echo foo >> out.txt || echo bar >> out.txt) && '
'echo baz >> out.txt', globals(), locals())
self.assertEquals('foo\nbaz\n', file('out.txt').read())
开发者ID:yunabe,项目名称:codelab,代码行数:4,代码来源:pysh_test.py
示例20: testReturnCode
def testReturnCode(self):
rc = pysh.run('rc <- echo foo >> /dev/null', globals(), locals())
self.assertEquals(1, len(rc))
self.assertEquals(0, rc['rc'])
开发者ID:yunabe,项目名称:codelab,代码行数:4,代码来源:pysh_test.py
注:本文中的pysh.run函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论