1

Is it possible to generate 2 different output windows with a different output on each of them (I'm on Windows 11)? For example, lets say there are 2 functions, a and b:

def a():
   print('This is output A')

def b():
   print('This is output B')

What I wanted to do is to get function a output on a console window, but get function b's output on another one. Instead of this

This is output A
This is output B

I need this

# WINDOW 1
This is output A
# WINDOW 2
This is output B
montw
  • 85
  • 10
  • with `print` function, you can control the output with the option `file`. By default, is something like `print(expression, file=sys.stdout)`. You should create your own `print` function using the `os` package for open a new console – L F Jan 29 '22 at 18:01
  • 2
    @LuisFelipe - Interesting design concept / hypothesis; care to add an answer to demonstrate this functionality in practice? – S3DEV Jan 29 '22 at 18:04
  • on the new consol, run the `print` statement. Something like `def my_print(text)` and use inside `os.system('python -h print("{}".format(text))')`, I think that `python -h` is the line for execute inline python code, you should google it. – L F Jan 29 '22 at 18:08
  • I'm not sure if this'd work on Windows, but on Linux, I might try creating two pipe files, opening terminals running `['cat', pipe]`, then [redirecting the function output](/a/22434262/45183410) to the pipes. It might be worth adding the [tag:Windows] tag to this question, idk. – wjandrea Jan 29 '22 at 18:24
  • Do these answer your question? [Outputting text to multiple terminals in Python](/q/22796476/4518341) and [Redirect stdout to a file in Python?](/q/4675728/4518341), as well as [Using Python's Subprocess to Display Output in New Xterm Window](/q/5558720/4518341) and [How can I create a tmp file in Python?](/q/8577137/4518341) If not, I wrote a proof-of-concept on Linux that might help. – wjandrea Jan 29 '22 at 18:53
  • @wjandrea thanks for the useful links! Luis Felipe i will try your solution – montw Jan 29 '22 at 19:47

1 Answers1

0

It is possible on windows but it is really hard to make it happen...

What you want to do is create a threaded server at the beginning of your program. Then with a client you can connect to the server. After connecting to the server you can send data to the client which it will print them. In addition you can to the oposite and controll the main file with the client. You can even take it as far as controlling the server from another device. Lastly if you code a good server you can have more than one terminal controlling or printing the output across diffrent devices.

petios
  • 25
  • 6