1
我想在计算机信息文件中自动记录我的python版本。然而如何让`python2 -V >> myfile`“工作”?
python2 -V >> myfile
仅打印到控制台,但不myfile
。我怎样才能得到输出到一个文件?
奇怪的是,对于python3 - python3 -V >> myfile
- 这工作正如我所料。
我在Ubuntu 16.04上,我使用bash shell。
我想在计算机信息文件中自动记录我的python版本。然而如何让`python2 -V >> myfile`“工作”?
python2 -V >> myfile
仅打印到控制台,但不myfile
。我怎样才能得到输出到一个文件?
奇怪的是,对于python3 - python3 -V >> myfile
- 这工作正如我所料。
我在Ubuntu 16.04上,我使用bash shell。
python2 -V
中存在一个错误,它将版本打印为stderr
而不是stdout
。尝试重定向stderr
,如:
python2 -V 2>> myfile
您需要重定向标准错误,就像这样:'python2 -V 2 >> myfile' –