【问题标题】:There was an error creating the child process for this terminal为此终端创建子进程时出错
【发布时间】:2021-01-22 15:58:00
【问题描述】:

我正在尝试启动一个新的 gnome 终端并执行一个命令

当我执行gnome-terminal时,一个新的终端顺利打开。

现在当我运行它时

gnome-terminal -- "zsh; echo hello"

我希望打开一个带有 zsh 的新终端,并打印 hello。

但我得到的是一个新的终端:

There was an error creating the child process for this terminal
Failed to execute child process “zsh; echo hello” (No such file or directory)

一些重要的结果

请看一下


❯ gnome-terminal -e "echo hello"
# Option “-e” is deprecated and might be removed in a later version of gnome-terminal.
# Use “-- ” to terminate the options and put the command line to execute after it.
❯ gnome-terminal --command "echo hello"
# Option “--command” is deprecated and might be removed in a later version of gnome-terminal.
# Use “-- ” to terminate the options and put the command line to execute after it.

执行以下几行,会在屏幕上执行一些幽灵动作,但不会产生可见的输出

❯ gnome-terminal --window -- echo hello
❯ gnome-terminal --tab -- echo hello
❯ gnome-terminal --tab -- echo hello
❯ gnome-terminal --tab --wait  -- echo hello

我在哪里犯错了?如何完成我的预期工作,即启动一个印有 hello 的新 zsh 终端,并等待下一个命令

【问题讨论】:

    标签: linux shell terminal zsh gnome-terminal


    【解决方案1】:

    发生的情况是您正在打开一个新终端,但在实际终端中运行这些命令。如果您想在新终端中运行这些命令,您必须指定-x 选项,这表示它将在将打开的终端中执行命令行的其余部分。现在,您可以编写命令,但您需要为 zsh 指定 -c 选项,以便 zsh 将第一个参数“逗号内的命令”作为命令。现在终端将执行命令,并保持打开状态,不会闪烁。但它没有外壳,我猜你想继续写命令,所以你需要exec zsh。就是这样。

    应该是这样的:

    gnome-terminal --x zsh -c 'echo hello; exec zsh'
    

    【讨论】:

    • 非常感谢您的回答。我尝试过这个。当前终端中的一个新选项卡已打开,打印了 hello 并等待输入。但是这个显示在原来的终端shell # Option “-x” is deprecated and might be removed in a later version of gnome-terminal. # Use “-- ” to terminate the options and put the command line to execute after it.
    • 这在我看来不是,可能是因为您的终端版本较新,或者因为发行版。尝试使用 -- 而不是 -x,我猜。尽管有这条信息,它有效吗?
    • 是的,这行得通。请使用-- 而不是-x 更新您的答案
    【解决方案2】:

    您的代码的第一行可能包含以下内容:

    #!/usr/bin/expect -f
    

    #!/bin/bash
    

    确保该目录存在。例如,您可能正在运行未安装的程序 expect。

    【讨论】:

      猜你喜欢
      • 2022-01-18
      • 1970-01-01
      • 2019-06-03
      • 2019-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-01
      相关资源
      最近更新 更多