在另一个xterm会话中启动python脚本

2024-09-30 06:29:43 发布

您现在位置:Python中文网/ 问答频道 /正文

这行代码让我很为难。我读过很多在新的终端窗口中启动python脚本的方法。我想我非常接近这一说法,但它似乎是扼杀我的道路。在

代码行是:

os.system("xterm -hold 'sudo python /home/pi/newcode/newcode/hms2-v2.5.py'")

错误消息是:

^{pr2}$

Tags: 方法代码脚本终端homeospisudo
3条回答
^{1}$

如前所述,您应该使用^{} option

-eprogram [ arguments ... ]
This option specifies the program (and its command line arguments) to be run in the xterm window. It also sets the window title and icon name to be the basename of the program being executed if neither -T nor -n are given on the command line.
NOTE: This must be the last option on the command line.

手册页面中有一个微妙的地方:当您省略-e时,xterm会尝试将整个引用字符串解释为shell解释器的名称。这是由于它实现localFilter的方式间接导致的:

When using a locale-filter, e.g., with the -e option, or the shell, xterm first tries passing control via that filter. If it fails, xterm will retry without the locale-filter. Xterm warns about the failure before retrying.

OPTIONS部分的开头有一些额外的讨论:

One parameter (after all options) may be given. That overrides xterm's built-in choice of shell program:

  • If the parameter is not a relative path, i.e., beginning with "./" or "../", xterm looks for the file in the user's PATH. In either case, this check fails if xterm cannot construct an absolute path.

所以。。。当你试过的时候

^{1}$

xterm试图找到一个名为

^{pr2}$

这不是你想要的。在

它在告诉你真相。当您运行xterm <thing>xterm将尝试在$PATH中找到一个名为<thing>的二进制文件。在本例中,您传递了一个长引号的字符串,但它仍然是一个参数,xterm很可能找不到它。在

对于您正在尝试的操作,您需要-e选项。从手册页:

^{1}$

所以:

^{pr2}$

相关问题 更多 >

    热门问题