Home > Back-end >  Is there a way to have a C or C program open a new terminal window and start executing code for yo
Is there a way to have a C or C program open a new terminal window and start executing code for yo

Time:07-08

I want to create a C or C program that automates some things for me.

The idea is as such: I run the program ./a.out and sit back and watch as it opens up three or four new terminal windows and runs various UNIX commands. Is there a way to do this?

I am on a MacBook.

CodePudding user response:

As the comments point out, this is probably best accomplished by a shell script. However, you can execute shell commands from C with the system(3) standard library function. To open a terminal, just run a terminal with a particular command. For example:

system("xterm -e 'echo hello; sleep 5'");

CodePudding user response:

Check this way to do it with bash you can find equivalent in c or c https://stackoverflow.com/a/989357/12302316

  • Related