简体   繁体   English

打开新终端并使其执行 C 中的命令时出现问题

[英]Troubles opening new terminal and make it execute a command in C

I'm currently on a school project, and I need to have a main program open 2 new terminals that will run other programs.我目前正在进行一个学校项目,我需要一个主程序打开 2 个将运行其他程序的新终端。

I've searched on internet, and found the system command, with x-terminal-emulator .我在互联网上搜索,找到了系统命令,使用x-terminal-emulator So I tried it in my program, and the terminal window open, but not the command I was putting behind.所以我在我的程序中尝试了它,终端 window 打开,但不是我放置的命令。 I'm trying to make it run ls.我试图让它运行 ls。

So far, I've tried:到目前为止,我已经尝试过:

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

I've searched on some man pages too, but can't seem to find anything helpful.我也搜索了一些手册页,但似乎找不到任何有用的东西。 Could anyone explain me please?谁能给我解释一下?

I'm on Ubuntu 18.04我在 Ubuntu 18.04

I cannot explain why your code does not work but the following code works on Centos 7.8.2003 using xterm and GNOME 3.8.22:我无法解释为什么您的代码不起作用,但以下代码使用xterm和 GNOME 3.8.22 在 Centos 7.8.2003 上工作:

#include <stdlib.h>
#include <stdio.h>

int main()
{

    system("xterm -e \"ls -l;sleep 5\"");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM