[英]Executing binary files using exec* in c
我正在创建一个玩具壳。 我想执行一个位于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.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.