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
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.