【问题标题】:Troubles opening new terminal and make it execute a command in C打开新终端并使其在 C 中执行命令时遇到问题
【发布时间】:2020-10-16 04:40:34
【问题描述】:

我目前正在进行一个学校项目,我需要一个主程序打开 2 个将运行其他程序的新终端。

我在互联网上搜索,找到了系统命令,x-terminal-emulator。所以我在我的程序中尝试了它,终端窗口打开了,但没有打开我后面的命令。我正在尝试让它运行 ls。

到目前为止,我已经尝试过:

system("x-terminal-emulator -e ls .");
system("x-terminal-emulator -x ls .");
system("x-terminal-emulator -e \"ls .\"");

我也搜索了一些手册页,但似乎找不到任何有用的东西。谁能给我解释一下?

我使用的是 Ubuntu 18.04

【问题讨论】:

    标签: c gnome-terminal terminal-emulator


    【解决方案1】:

    我无法解释为什么您的代码不起作用,但以下代码使用 xtermand GNOME 3.8.22 在 Centos 7.8.2003 上运行:

    #include <stdlib.h>
    #include <stdio.h>
    
    int main()
    {
    
        system("xterm -e \"ls -l;sleep 5\"");
    }
    

    【讨论】:

    • 感谢您的回答!不幸的是,它不适用于我的程序。终端甚至没有显示 system() 命令。不过,它确实会在终端中使用命令 xterm 显示。我已经编辑了我的帖子以显示我的分布。
    猜你喜欢
    • 1970-01-01
    • 2020-05-14
    • 2021-12-09
    • 2016-10-20
    • 2016-10-09
    • 2015-11-04
    • 1970-01-01
    • 2015-07-22
    • 1970-01-01
    相关资源
    最近更新 更多