打开一个新的终端窗口用C [英] Opening a new terminal window in C

查看:577
本文介绍了打开一个新的终端窗口用C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有成功编译生成一个可执行的C程序,我怎么指导程序,当我从一个pre-现有终端命令提示符下的命令行运行它打开一个新的终端窗口?我想我使用系统()功能,但什么头是在和什么是实际的命令ARG需要吗?

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 a pre-existing terminal command prompt? I assume I use the system() function but what header is that in and what is the actual command arg it takes?

推荐答案

头文件是文件stdlib.h 和函数签名是 INT系统(为const char *命令)。所以你的情况,你可以这样调用该函数生成一个新的终端窗口:

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

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

在C这是常见的检查大多数函数的返回值调用,以确定是否发生了错误或获得有关呼叫的更多信息。在系统()调用返回运行的命令的退出状态,并且在这里保存在 EXIT_STATUS 作进一步检查。

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.

请参阅人系统详细。

这篇关于打开一个新的终端窗口用C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆