Why does popen() invoke a shell to execute a process?

前端 未结 3 1888
温柔的废话
温柔的废话 2021-02-20 12:13

I\'m currently reading up on and experimenting with the different possibilities of running programs from within C code on Linux. My use cases cover all possible scenarios, from

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-20 12:43

    The glib answer is because the The POSIX standard ( http://pubs.opengroup.org/onlinepubs/9699919799/functions/popen.html ) says so. Or rather, it says that it should behave as if the command argument is passed to /bin/sh for interpretation.

    So I suppose a conforming implementation could, in principle, also have some internal library function that would interpret shell commands without having to fork and exec a separate shell process. I'm not actually aware of any such implementation, and I suspect getting all the corner cases correct would be pretty tricky.

提交回复
热议问题