【发布时间】:2014-04-20 18:58:36
【问题描述】:
这个标题可能令人困惑,但基本上我希望能够做到以下几点:
import subprocess
subprocess.call(["python"])
subprocess.call(["import", "antigravity"])
subprocess.check_call(["print","\"This is so meta\" "])
subprocess.call(["exit()"])
预期的行为是它会打开一个 python 终端会话,然后打开 xkcd comic 353,在命令行中打印 'this is so meta',最后退出 python 命令行。
基本上,我希望能够打开一个 python 会话,并从我的 python 脚本中运行命令。我还希望能够检查我在脚本中运行的命令的输出。这可能吗?如果是这样,我需要使用什么库?子进程会这样做吗?
【问题讨论】:
-
那么,看起来你想要你自己的python命令?我说的对吗?
-
是的,我希望能够在 python 中调用我自己的命令。来自一个单独的 python 脚本。
-
你想要你的 python 脚本的位置和方式??
-
我要运行的 python 脚本将是上面列出的命令。我希望能够运行并在“python 命令行”中执行命令,就像我在问题中写的那样。
标签: python subprocess