Running a command from C ++, what is expected in argv [0]?

I use execv()to run commands from / bin /, such as 'ls', 'pwd', 'echo' from my C ++ program, and I wonder what value I should provide in argv [0];

const char * path = getPath();
char ** argv = getArgs();

execv(path,argv);
+3
source share
3 answers

argv[0]must be the name of the program. He switched to the function of the program main. Some programs distinguish their behavior depending on which line argv[0]. For example, the GNU shell bashwill disable some of its functions if called using shinstead bash. It is best to give it the same meaning as on path.

linux argv[0] - , top (, , /proc/)

+12

argv [0] , .

+5

, , , , ? , , , , , system() execv(), Windows Unix , . , , PATH , .

If you transfer the string, in whole or in part, and run it, you also leave yourself open to the user accessing the system by entering a command that may be corrupted. For instance. Imagine you have implemented a file search with find /home -name, and your users:

"%" -exec rm {} \;

Oh!

+2
source

Source: https://habr.com/ru/post/1735073/


All Articles