我今天注意到,apt的行为取决于何处(shell / python /.)它是从。
背景我正试图通过apt CLI找出“手表”的提供包。这也很好地手动工作:
apt-get install -s watch
NOTE: This is only a simulation!
apt-get needs root privileges for real execution.
Keep also in mind that locking is deactivated,
so don't depend on the relevance to the real current situation!
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'procps' instead of 'watch'
procps is already the newest version (2:3.3.15-2).
procps set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 15 not upgraded.最重要的是Note, selecting 'procps' instead of 'watch':显然,手表是由procps提供的。到目前一切尚好。
当我从python的subprocess库执行相同的命令时,这一行就消失了。有了os.system,它又开始工作了。
因此,我试图通过简单地将命令行(stdout和stderr)的输出传递到日志文件(apt-get install -s watch &> /tmp/output)结果中来调查这个问题:
NOTE: This is only a simulation!
apt-get needs root privileges for real execution.
Keep also in mind that locking is deactivated,
so don't depend on the relevance to the real current situation!
Reading package lists...
Building dependency tree...
Reading state information...
procps is already the newest version (2:3.3.15-2).
procps set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 15 not upgraded.线路不见了。
之后,我在apt的源代码中搜索了一下,找到了对应线。这里的输出流是out,其他一些ioprintf部分正在使用c1out。看来这是另一条小溪..。但是为什么我的终端打印这个流的输出,而大多数其他程序都无法处理它呢?
发布于 2021-07-26 13:07:41
根据输出是否为tty,apt的行为不同。
如果它的stdout不是,它的行为就像--quiet=1被传递给它一样。
您可以通过明确地传递--quiet=0来省略这种行为。
apt-get --quiet=0 install -s watch | less手册可以告诉我们更多关于--安静。
请注意:这很可能是一个不好的想法,依靠一些apt开发人员变得更难管道,甚至grep/awk。
发布于 2021-07-26 12:40:31
您是从虚拟env运行os.system吗?这是很有可能的。
https://stackoverflow.com/questions/68529911
复制相似问题