0

这是我.fluxbox/startup文件 的一部分

(a=($(grep "^1 " $HOME/Documents/4.n3u|awk '{print "/home/g" $2}'|sort -R|head -20)); \  
  xterm -e mpg123 -C ${a[@]} &>$HOME/Documents/mpg123.dat &)  

如所写,重定向失败,所有此类输出都出现在xtermxterm部分读取 的手册页,

   -e program [ arguments ... ]
           This  option  specifies the program (and its command line argu‐
           ments) 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.
           This must be the last option on the command line.

mpg123根据需要播放数组 a 的内容,并且可以根据选项-C指定通过键盘进行控制,但xterm似乎会阻碍重定向到文件。在这种情况下可以进行重定向吗?

或者,我可以在没有xtermto contain的情况下运行它mpg123,在这种情况下,我会获得重定向,但无法mpg123通过键盘进行控制,因为它在某些后台子shell 中运行而没有与键盘的连接。有没有办法建立这种联系?

4

1 回答 1

1

您已经重定向了xterm进程的 stdout 和 stderr,但 xterm 通常不会在其自己的 stdout 和 stderr 上打印任何内容。唯一会出现与 xterm 本身相关的错误(例如,如果它意外失去与 X 服务器的连接)。

xterm 创建一个 tty 并运行-e带有附加到该 tty 的 stdin、stdout 和 stderr 的子进程(命令或 shell)。您需要将重定向放在内部-e以使其在子进程中应用,如下所示:

xterm -e 'your command > whatever'

第二次尝试

为了保持${a[@]}参数列表完整但也使用 shell 重定向运算符,您将不得不显式调用带有-c. 像这样:

xterm -e sh -c 'your command "$@" > whatever' dummy "${a[@]}"
于 2013-06-23T19:32:39.860 回答