views:

61

answers:

2

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 :)

A: 

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.

regulus6633
A: 

That's not what I meant.

I'll try to explain.

When you have written an app, let's say GUI one, you often leave print instructions in it. And when you make it executable and open it by clicking it's icon you cant see what it prints to the stdout. In order to see that you have to start your app in terminal. Then program works normally and you have everything printed in terminal.

I guess that most of u know what I mean.

And now there is a situation when I started my program by clicking it's icon and what I want to do is "connect" to it AFTER I started it and get it's stdout and stdin.

I've tried named pipes(fifo's) for it and they seem to be promising, but still looking for a better solution.

Do you have any?