python - 是否可以在 shell 命令中的反引号之间执行 Python 程序?

标签 python shell backticks

我正在尝试执行一个 Python 程序,将其输出重定向到一个文件,并将该文件的内容与现有文件进行比较,所有这些都在一个 shell 命令中完成。这就是我所拥有的,但当然它不起作用:

diff `python3 program.py > redirect_file.txt` compare_file.txt

我是 Linux 菜鸟,所以任何能为我指明正确方向的帮助都会很棒。

最佳答案

diff 命令允许您在命令行上使用- 来使用stdin,所以尝试:

python3 program.py | diff - compare_file.txt

关于python - 是否可以在 shell 命令中的反引号之间执行 Python 程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21222342/

相关文章:

linux - Tcpdump 命令 - Linux - Unix

linux - 执行 ls -lh 命令

powershell - 了解如何在记事本中使用反引号(MS)

mysql - Bash 和 MySQL 变量错误

bash - 在 shell 脚本中使用 $() 代替反引号有什么好处?

python - 在 Python 中 fork 多个 shell 命令/进程的最佳方法?

python - 具有对角矩阵的点积,无需创建完整矩阵

Python 转换汉字

python - KIVY:在 Paint App 中更改线条颜色

python - 如何在python中表示矩阵