gpt4 book ai didi

Python & macOS : open new Terminal window from Python, 传递要执行的命令

转载 作者:太空宇宙 更新时间:2023-11-03 11:18:17 25 4
gpt4 key购买 nike

我正在使用以下两行 Python 代码从 Python 脚本打开一个新的终端窗口,这工作正常:

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

现在我想向新的终端窗口传递一个要执行的命令,例如

ls

我该怎么做?

最佳答案

试试这个

import appscript

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

关于Python & macOS : open new Terminal window from Python, 传递要执行的命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48408278/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com