如何在Python中运行命令行脚本

时间:2018-09-25 02:22:13

标签: python-3.x

如果我有这样的命令行:

abc -c config.json| xyz -c test.json

如何在Python文件中运行它?我的意思是我们不会在终端中键入“ abc -c config.json| xyz -c test.json”。 xyzabc是我编写的应用程序。

那么,我可以帮忙吗?

2 个答案:

答案 0 :(得分:1)

您可以使用此

os.system("abc -c config.json| xyz -c test.json")

这就像在命令提示符下运行abc -c config.json| xyz -c test.json

答案 1 :(得分:0)

您的问题让我有些困惑。

如果要从python中进行系统调用,则可以使用子流程模块

x = subprocess.Popen("ls /home", shell=True, stdout=subprocess.PIPE).stdout.read()

如果要从命令行运行python命令,可以将其写入文件并执行

python myFile.py

或者,直接将命令运行到python

python -c "print("testing")"
相关问题