gpt4 book ai didi

linux - 如何为 openvt 重定向 stderr

转载 作者:太空宇宙 更新时间:2023-11-04 11:25:53 27 4
gpt4 key购买 nike

我必须在特定的 tty 上启动我的 TextUI 守护程序重生。为此,我从脚本启动它,如下所示:$set_tty $launch_app,其中

  • set_tty="openvt -c1 -s -w",
  • launch_app="my_daemon 2>'$HOME'/logfile"

通过这种方式,我启动了看起来像 openvt -c1 -s -w my_daemon 2>'$HOME'/logfile 的命令,它仅重定向到指定的日志文件,只有来自 的 stderr openvt 本身,但不是来 self 的守护程序。

如何重定向 openvt 的被调用者 stderr?

我尝试使用函数:

go () { my_daemon 2>"$HOME"/logfile; }
openvt -c1 -s -w

它不工作,opentty 立即返回控制产生任何东西。

我试过 exec 2>>"$HOME"/logfile

我尝试使用该功能启动一个单独的脚本。该脚本无法通过 openvt 运行,但如果我使用相同的参数手动启动它,则运行正常。

我错过了什么?

最佳答案

一个可能的答案可能是包装器 shell 脚本,其内容将负责生成您的守护进程,并将 stderr 重定向到您选择的日志文件。

[anew@bucket ~]$ cat test.sh 
#!/bin/bash
echo "Testing openvt" > /tmp/openvt-example

[anew@bucket ~]$ sudo openvt -c7 -s -w /home/anew/test.sh
[anew@bucket ~]$ cat /tmp/openvt-example
Testing openvt
[anew@bucket ~]$

关于linux - 如何为 openvt 重定向 stderr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14814414/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com