Reputation: 875
To run a c program you do something like this
bash> gcc test.c -o test
and then
bash> ./test
How can i do to make test.c execute a terminal in another window??
Upvotes: 1
Views: 6281
Reputation: 1999
You can fork a new process and use system() function. This will work on most of Linux distributions. Just check the terminal properties to know the command to execute a new terminal. "gnome-terminal" works for me(Ubuntu, Redhat).
int main()
{
if(!fork())// child process
system("gnome-terminal");
else
{
//do rest of the things here in parent process......
}
}
After fork(), a new terminal window will open as a separate process.
Upvotes: 2
Reputation: 26281
Based on your use of the word terminal
im guessing you are using osx.
You can use applescript to get the behavior:
tell application "Terminal"
activate
do script with command "cd _directory_; ./test"
end tell
If you want the program to launch a window, have the program call popen to launch the command [or write to a temporary file and launch the script]
Upvotes: 0
Reputation: 852
xterm -e "./test"
This will execute 'test' in a new xterm window. Assuming Linux of course.
Upvotes: 2
Reputation: 12719
You want to open a window for a new terminal, or what do you want to do? Your question isn't really clear.
If you want to run some commands, you need to cope with sys calls to launch a new process.
On Windows there's the system() function, but I'm not sure it exists on Linux or other posix systems.
Upvotes: 0
Reputation: 421160
Depends on which system you're on and which terminal you have in mind, but here's how to do it if you're on gnome (ubuntu for instance)
gnome-terminal -x sh -c "./test"
If you don't want the window to close immediately after ./test
finishes, you do
gnome-terminal -x sh -c "./test; cat"
Upvotes: 0