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

标签 c shell exec

我正在创建一个玩具 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/ 成为我的参数等。

最佳答案

来自execl's documentation

 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/

相关文章:

c++ - C中如何跳转程序执行到特定地址?

python - 在python中执行相关os命令

linux - 在 shell 脚本中将脚本目录更改为用户的主目录

linux - 将 stdout 和 stderr 恢复为默认值

c - 内存分配给纯 C 中的结构

c - C语言中使用循环反转字符串

python - 在 VBA 中,如何使用 Shell.Run 而不是 Shell.Exec 来捕获 shell 输出?

后台错误中的php exec c程序

java - 在JAVA中捕获外部程序的输出

c# - C to C# CRC计算转换器