我正在创建一个玩具 shell 。我想执行一个位于 PATH 变量或当前目录中的二进制文件。这就是我为实现这一目标所做的事情:
execl(filePath," -e ",com.arguments,NULL); //e.g of filePath: /home/dino/programs/mywrapper
现在它对于某些可执行文件(例如 which
命令)可以正常工作。但对于像 tar
这样的命令,会抛出一大堆错误。
基本上,我想要的只是 execl
在我的 shell 中执行 filePath
中提到的可执行文件。我该怎么做?
编辑:
com.arguments
是参数列表。例如,在 which bash
中,bash
成为我的论点。在 tar -zvcf bazinga.tar.gz bazinga/
中,-zvcf bazinga.tar.gz bazinga/
成为我的参数等。
最佳答案
The first argument, by convention, should point to the
filename associated with the file being executed.
关于c - 在c中使用exec*执行二进制文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21333167/