parsing - How can I execute a command with multiple arguments in my shell in C? -


i want shell able run

cat file.txt  

as as

ls -l 

i'm not sure how this, because cat 2nd argument text file, however, commands such ls 2nd argument not, have execute differently. not sure how handle both cases properly.

your shell should looking matching binary first parameter , passing in subsequent parameters strings first program. shell isn't responsible determining parameters mean, program runs is.

your shell should call fork(), in child process (where return value of fork() == 0), call 1 of different exec commands run user-specified program. meanwhile, original process waiting on fork'd child complete waitpid().

http://linux.die.net/man/3/exec

you see many of take array of character pointers parameter. you'll pass in subsequent parameters exec'd binary read in , parse itself.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -