[英]Executing binary files using exec* in c
I am creating a toy shell. 我正在创建一个玩具壳。 I want to execute a binary file which is either located in the PATH variable or the current directory.
我想执行一个位于PATH变量或当前目录中的二进制文件。 This is what I am doing to achieve it:
这是我正在实现的目标:
execl(filePath," -e ",com.arguments,NULL); //e.g of filePath: /home/dino/programs/mywrapper
Now it works fine for some executables like which
command. 现在,它对于某些可执行文件(例如
which
命令)可以正常工作。 But for commands like tar
, a whole bunch of error throws up. 但是对于诸如
tar
命令,则会引发大量错误。
Basically all I want is the execl
to execute the executable mentioned in filePath
in my shell. 基本上,我只需要
execl
来执行shell中filePath
中提到的可执行文件。 How do I do it? 我该怎么做?
EDIT: com.arguments
is the arguments list. 编辑:
com.arguments
是参数列表。 For example in which bash
, bash
becomes my argument. 例如,在
which bash
, bash
变成我的论点。 In tar -zvcf bazinga.tar.gz bazinga/
, -zvcf bazinga.tar.gz bazinga/
becomes my arguments etc. 在
tar -zvcf bazinga.tar.gz bazinga/
, -zvcf bazinga.tar.gz bazinga/
成为我的论点,等等。
From execl
's documentation 从
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.