0

例如,

subprocess.Popen(["/usr/bin/vlc", "--version"], stderr=subprocess.PIPE, stdout=subprocess.PIPE).communicate()

在我的电脑上导致

('VLC version 2.0.2 Twoflower (.....see the AUTHORS file.\n', '')
# longish text in stdout with versions, including GCC version, date
# nothing on stderr

在其他计算机上它导致

('', 'VLC media player 1.1.3 The Luggage (revision exported)\n')
# on stderr

还有(奇怪):

mycomp> /usr/bin/vlc --version 2>&1 > /dev/null
VLC media player 2.0.2 Twoflower (revision 2.0.1-453-g40d9fef)
mycomp> perl -e 'print `/usr/bin/vlc --version 2>&1 > /dev/null`'
(no output at all)
mycomp> /usr/bin/vlc --version 2>&1 > /dev/null | cat
(no output at all)
mycomp> socat system:'/usr/bin/vlc --version > /dev/null',stderr -
(no output at all)
mycomp> socat system:'/usr/bin/vlc --version > /dev/null',pty,stderr -
VLC media player 2.0.2 Twoflower (revision 2.0.1-453-g40d9fef)
mycomp> strace -o /tmp/2 -e write  /usr/bin/vlc --version 2>&1 > /dev/null | cat
(no output at all)
mycomp> cat /tmp/2
write(1, "VLC version 2.0.2 Twoflower (2.0"..., 401) = 401
mycomp> strace -f -o `tty` -e write  /usr/bin/vlc  --version > /dev/null 2> /dev/tty2
3628  write(2, "VLC media player 2.0.2 Twoflower"..., 63) = 63
3628  write(1, "VLC version 2.0.2 Twoflower (2.0"..., 401) = 401
strace -f -o `tty` -e write  /usr/bin/vlc  --version > /dev/null 2> /dev/null
3587  write(1, "VLC version 2.0.2 Twoflower (2.0"..., 401) = 401
# sad, seems to be "too clevel"-type of bug.


othercomp> perl -e 'print `/usr/bin/vlc --version 2>&1 > /dev/null`'
VLC media player 1.1.3 The Luggage (revision exported)
othercomp> /usr/bin/vlc --version 2>&1 > /dev/null
VLC media player 1.1.3 The Luggage (revision exported)

怎么了?我应该依靠什么?

4

1 回答 1

1

看起来他们将输出--version从标准错误切换到标准输出。你必须同时检查两者。

于 2012-08-10T00:44:46.220 回答