在Linux中,可以使用 system 函数执行命令。system 函数的原型如下:
```c
int system(const char *command);
```
其中,`command` 参数是要执行的命令。
下面是一个简单的示例,展示如何使用 system 函数来执行命令:
```c
#include
#include
int main()
{
int result = system("ls -l");
printf("Command executed with result code: %d\n", result);
return 0;
}
```
上面的代码会执行 `ls -l` 命令,并打印命令的执行结果。system 函数会返回命令的退出状态码,如果命令执行成功,返回值一般为 0。如果命令执行失败,返回值一般为其他非零值。