简体   繁体   中英

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. 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. But for commands like tar , a whole bunch of error throws up.

Basically all I want is the execl to execute the executable mentioned in filePath in my shell. How do I do it?

EDIT: com.arguments is the arguments list. For example in which bash , bash becomes my argument. In tar -zvcf bazinga.tar.gz bazinga/ , -zvcf bazinga.tar.gz bazinga/ becomes my arguments etc.

From execl 's documentation

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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