Opening a new terminal window in C

前端 未结 3 582
忘掉有多难
忘掉有多难 2021-01-21 00:06

If I have a C program that I compile successfully and generate an executable, how do I instruct the program to open a new terminal window when I run it from the command line in

3条回答
  •  悲&欢浪女
    2021-01-21 00:29

    The header file is stdlib.h and the function signature is int system(const char *command). So in your case you could call the function like this to spawn a new terminal window:

    #include 
    
    int main(void) {
        int exit_status = system("gnome-terminal");
    }
    

    In C it's common to check the return value of most function calls to determine if something went wrong or to get some more information about the call. The system() call returns the exit status of the command run, and is here stored in exit_status for further inspection.

    See man system for the details.

提交回复
热议问题