Are system() calls evil?

后端 未结 6 1685
臣服心动
臣服心动 2020-12-03 21:07

I am designing an C++ app that, among other things, executes a few scripts every now and then. The app should be efficient and preferably platform independent.

The i

6条回答
  •  遥遥无期
    2020-12-03 21:57

    Whatever command you want to execute just store that in a file c.txt. Pass that file to the execl() like as done below.

    fd = open("c.txt", O_CREAT | O_RDWR, 00777);
    write(fd,arr,sizeof(arr));
    if(fork() == 0)
    {
        execl("/bin/sh", "sh", "-c","sh c.txt", (char *) 0);
    }
    

提交回复
热议问题