简体   繁体   中英

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.

I've searched on internet, and found the system command, with x-terminal-emulator . So I tried it in my program, and the terminal window open, but not the command I was putting behind. I'm trying to make it run 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

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:

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

int main()
{

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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