繁体   English   中英

在C中使用exec *执行二进制文件

[英]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 bashbash变成我的论点。 tar -zvcf bazinga.tar.gz bazinga/-zvcf bazinga.tar.gz bazinga/成为我的论点,等等。

execl的文档

 The first argument, by convention, should point to the
filename associated with the file being executed.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM