连接到现有进程

发布于 2024-09-04 20:52:12 字数 282 浏览 3 评论 0原文

mac os x 上发生了漏洞。

假设我通过单击 .app 图标打开了一个程序。它是一个带有 GUI 的 python 程序,有一个单独的进程等待用户输入。但是,当我通过单击 .app 图标打开它时,我无法像在终端中打开它一样访问它的输入。

问题是:

如何将新的终端窗口连接到这个正在运行的程序?我尝试过管道,但我不确定如何正确使用它们。我的猜测是找到正在运行的应用程序的 PID,然后通过给出 PID 管道到该程序。但我不知道该怎么做。

我希望您能够理解问题所在。抱歉我的英语很差:)

Hole thing is happening on the mac os x.

Let's assume that I've opened an program by clicking on an .app icon. It's a python program with GUI which has a separate process that waits for a user input. But as I've opened it by clickin .app icon I dont have access to it's input as I would have if I opened it in Terminal.

And the question is:

How can I connect new Terminal window to this running program? I tried pipes but I'm not sure how to use them correctly. My guess was to find PID of the app that is running and then pipe to this program by giving a PID. But I have no idea how to do it.

I hope you were able to understand what's the problem. Sorry for my weak english :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心房的律动 2024-09-11 20:52:12

如果您需要将终端窗口连接到“单独的进程”,我将使用终端在 python 脚本中启动该进程。我可以用一些 applescript 代码来做到这一点。这是一个简单的 applescript 示例。我可以打开一个终端窗口并运行“cd”命令,如下所示:

tell application "Terminal"
    activate
    do script with command "cd /"
end tell

所以现在你只需要弄清楚如何从 python 运行 applescript...我不知道。

If you need to have a Terminal window connected to your "separate process", I would use the Terminal to launch that process in your python script. I can do that with some applescript code. Here's a simple applescript example. I can open a Terminal window and run the "cd" command like this:

tell application "Terminal"
    activate
    do script with command "cd /"
end tell

So now you just need to figure out how to run an applescript from python... which I don't know.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文