How can I open two consoles from a single script

前端 未结 6 1145
渐次进展
渐次进展 2020-11-29 05:32

Apart from the scripts own console (which does nothing) I want to open two consoles and print the variables con1 and con2 in different con

6条回答
  •  心在旅途
    2020-11-29 05:58

    I don't know if it suits you, but you can open two Python interpreters using Windows start command:

    from subprocess import Popen
    p1 = Popen('start c:\python27\python.exe', shell=True)
    p2 = Popen('start c:\python27\python.exe', shell=True)
    

    Of course there is problem that now Python runs in interactive mode which is not what u want (you can also pass file as parameter and that file will be executed).

    On Linux I would try to make named pipe, pass the name of the file to python.exe and write python commands to that file. 'Maybe' it will work ;)

    But I don't have an idea how to create named pipe on Windows. Windows API ... (fill urself).

提交回复
热议问题