Python & macOS: open new Terminal window from Python, passing command to be executed

。_饼干妹妹 提交于 2020-03-21 20:46:10

问题


I am using the following two lines of Python code to open a new Terminal window from a Python script, and this works fine:

import os
os.system('open -a Terminal .')

Now I would like to pass the new Terminal window a command to be executed, for example

ls

How can I do that?


回答1:


Try this

import appscript

appscript.app('Terminal').do_script('ls')  # or any other command you choose


来源:https://stackoverflow.com/questions/48408278/python-macos-open-new-terminal-window-from-python-passing-command-to-be-exec

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!