用python脚本将stdin发送到子进程

2024-09-25 08:25:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个python脚本,它需要打开另一个终端窗口来发送一些命令。Stackoverflowers已经让我走了那么远:

import subprocess
server_terminal = subprocess.Popen(['open','-a','/Applications/Utilities/Terminal.app','/Applications/Utilities/Terminal.app']) #Not sure about the inelegance of the doubled path, but it does open another terminal window, which I need.

下一步,我需要向这个终端发送一些命令,这样我就可以在用户的桌面上设置一个本地服务器。在计算如何控制此子进程时遇到一些重大问题。在

有人能告诉我如何让这个终端子进程从我这里拿走stdin吗?我宁愿避免第三方模块。在

{我的主要目标是在一个单独的窗口中编辑一个命令。我已经知道如何控制服务器一旦启动,我只是不知道如何自动启动一个。在

谢谢你的帮助!在


Tags: theimport命令服务器脚本app终端进程
1条回答
网友
1楼 · 发布于 2024-09-25 08:25:42

您可以使用Popen直接启动服务器:

selenium_jar = '/full/path/to/selenium-server-standalone-2.0b3.jar'
path_to_fifo_profile = '...'

# start external process
p = subprocess.Popen(['java', '-jar', selenium_jar, 
                              '-firefoxProfileTemplate', path_to_fifo_profile,
                     ])
# wait for it to finish before exiting
p.wait()

如果要查看输出,可以使用os.system

^{pr2}$

相关问题 更多 >