c++ - 使用arm-none-linux-gnueabi-g++编译时不执行system()

标签 c++ linux unix

#include <stdio.h>
#include <stdlib.h>

int main()
{ 
    printf("Hello\n");
    system("echo nikhil");   
    printf("Hello\n");
    getchar();
    return 0;
}

当使用arm-none-linux-gnueabi-g++编译此代码时,系统调用将被跳过,除system("echo nikhil")之外的所有其他指令都会被执行

为什么会发生这种情况以及如何避免该问题?

最佳答案

system() will not, in fact, work properly from programs with set-user-ID or set-group-ID privileges on systems on which /bin/sh is bash version 2, since bash 2 drops privileges on startup... http://linux.die.net/man/3/system

您可以尝试使用Exec命令 http://linux.die.net/man/3/exec

关于c++ - 使用arm-none-linux-gnueabi-g++编译时不执行system(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24367623/

相关文章:

linux - Git 建议在 Linux 上的 Windows 上进行开发

Linux Bash sed 命令

java - 使用 Runtime.exec() 从 Java 程序运行 ASP 程序时出现问题

c++ - Pthread读写锁问题

sql-server - 如何在 Ubuntu 上使用 sqlcmd 调用带有 xml 参数的存储过程

c++ - qt中如何在窗体之间传递数据

linux - 使用 bash 将子目录扁平化并在文件名前加上目录名

linux - 使用 Linux 命令 head 和 tail

c++ - 为什么 GCC 为 0.0/0.0 产生 -nan 和 clang 和 intel 产生 +nan?

c++ - 套接字监听不会在 linux 下的 C++ 中解除绑定(bind)