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)
什麼是錯的?我應該依靠什麼?
看起來像VLC 2輸出良好的可解析版本格式兼容VLC 1 stderr ...但只有當stderr在tty上... – 2012-08-10 00:51:55