繁体   English   中英

在新的终端窗口中打印

[英]print in new terminal window

我编写了一个具有多个线程的脚本,在该线程中,我使用“ print()”代码来打印有关该线程的日志活动,但是问题是我不想在一个终端窗口中打印所有这些日志。 我在ubuntu论坛上找到了此代码,但它似乎不是一种可以在任何操作系统(包括mac,ubuntu,fedora等)上运行的标准方式...是否有任何标准方法可以在多个终端窗口或任何更好的ida中发布数据比这段代码?

import subprocess

pid = subprocess.Popen(args=["gnome-terminal", "--command=python test.py"]).pid
print pid

很难理解您从问题中表达的意思,但是以下内容可能会有所帮助。 在OSX上启动终端,然后按Command-N以获得第二个终端-这样您就有2个终端打开。 现在单击任一并键入:

tty

它将告诉您与该窗口关联的终端的名称,例如/dev/ttys000

然后在另一个打开的“终端”窗口中输入:

echo Hello > /dev/ttys000        # or whatever the other Terminal was called

您应该看到echo命令的输出出现在另一个终端的窗口中,我认为这就是您的意思。

一个shell(即Bash)实际上并不知道多个窗口。 您可以使用screen来管理多个Shell会话。

例如,创建一个新的屏幕会话并在其中执行ifconfig

#create a unique name for the screen session (timestamp + random muber)
timestamp_random=my_$(date +%s)_$RANDOM
#create new screen session in detached mode
screen -S "$timestamp_random" -d -m
#stuff (write) command into that screen session + execute (by hitting newline/ENTER)
screen -r "$timestamp_random" -X stuff $'ifconfig\n'

然后,您可以使用以下命令列出所有屏幕会话:

screen -list

并连接到每个会话以查看输出:

screen -R [sessionname]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM