Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

execl

Status
Not open for further replies.

cmancre

Programmer
Joined
Jan 30, 2005
Messages
35
Location
PT
i did a script in bash and i want to run it with few arguments.

#define rr "/path...."
execl(rr,"rr",arg1,arg2,arg3,arg4,arg5,arg6,(char *)0);

is this correct????
 
The execl function call isn't like system. execl must be used with the fork call:

Code:
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>

/* perform a unix/linux ls command on argument 1 */
int main(int argc, char* argv[])
{
int pid;

 switch(pid=fork())
      {
      case -1:
         fatal("fork error 1");
      case 0:
         execl("/bin/ls","ls","-l",argv[1],NULL);
         fatal("exec call 1 ");
       }
 /* wait for child process to finish */
 while(wait((int *)0) != pid)
   ;

printf("ending fork\n");

}

int fatal(char str[])
{
printf("%s\n");
exit(1);
}
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top