Tag: 管道

检索subprocess.call()的输出

我怎样才能得到使用subprocess.call()进程运行的输出? 将一个StringIO.StringIO对象传递给stdout会产生这样的错误: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 444, in call return Popen(*popenargs, **kwargs).wait() File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 588, in __init__ errread, errwrite) = self._get_handles(stdin, stdout, stderr) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 945, in _get_handles c2pwrite = stdout.fileno() AttributeError: StringIO instance has no attribute 'fileno' >>>

为什么在管道代码块内部延迟扩展会失败?

这里是一个简单的批处理文件,演示如果延迟扩展失败,如果它在一个正在管道的块内。 (失败是脚本的结尾)任何人都可以解释为什么这是? 我有一个解决方法,但它需要创建一个临时文件。 我最初遇到这个问题,同时在Windows批处理文件中查找文件和按大小排序 @echo off setlocal enableDelayedExpansion set test1=x set test2=y set test3=z echo( echo NORMAL EXPANSION TEST echo Unsorted works ( echo %test3% echo %test1% echo %test2% ) echo( echo Sorted works ( echo %test3% echo %test1% echo %test2% ) | sort echo( echo ——— echo( echo DELAYED EXPANSION TEST echo Unsorted works […]