Here are some common solutions in Linux.
To achieve this, you usually need two programs.
File i/o + Loop
:
- main program + file writer (print Op1 and write Op2 into file A)
- file reader (keep fetching A file until it be modified and print the content of file A)
Socket (pipe)
:
- main program + sender (print Op1 and send Op2 to a specific socket)
- receiver (listen a specific socket and print Op2 while receiving things)
File i/o + Signal
:
- main program + file writer + signal sender (print Op1 and write Op2 into file A and send signal to the daemon receiver)
- signal receiver (halt until receiving signal and print the content of file A)
By the way, I suppose that your requirement does not need to write any daemon program because you have certainly two consoles.
Additionally, I am pretty sure that printing on specific console is achievable.
Example of second solution [Socket]
# print1.py (your main program)
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(('localhost', 8001))
Op1 = 'Op1'
Op2 = 'Op2'
print Op1
sock.send(Op2)
sock.close()
Steps
// a. console 2: listen 8001 port
// Luckily, nc(netcat) is enough to finish this without writing any code.
$ nc -l 8001
// b. console 1: run your main program
$ python print1.py
Op1
// c. console 2
Op2