开发者

execute terminal from c program

To run a c program you do something like this

bash> gcc test.c -o test

and then

bash开发者_JAVA百科> ./test

How can i do to make test.c execute a terminal in another window??


xterm -e "./test"

This will execute 'test' in a new xterm window. Assuming Linux of course.


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.


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"


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.


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]

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜