2012-08-10 52 views
0

例如,如何从Python可靠地确定/ usr/bin/vlc的版本?

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) 

什么是错的?我应该依靠什么?

回答

1

看起来他们把--version的输出从stderr切换到stdout。你必须检查两者。

+0

看起来像VLC 2输出良好的可解析版本格式兼容VLC 1 stderr ...但只有当stderr在tty上... – 2012-08-10 00:51:55