Execute C Program

How will you execute a file from another C program through C programming without system command?

Questions by tejpreetsingh84

Showing Answers 1 - 12 of 12 Answers

rstalekar

  • Dec 10th, 2009
 

Just fork and do a execlp for that particular file. For eg:-
File test.c
int main()
{
printf("Hin");
return 0;
}

Compile cc test.c -o test

File try.c
int main()
{
   if ((pid=fork()) == 0)
  {
      execlp("./test","./test",NULL);
  }
  else
  {
     pid = wait(&status);
   }
}

  Was this answer useful?  Yes

abhimanipal

  • Jan 15th, 2010
 

The question here asks "how to run another progam without using a system call". I do not think it is possible to run another program without using exec.

  Was this answer useful?  Yes

yassiguy

  • May 25th, 2010
 

We can store a shell code in another file. The shell code will spawn the new program. We can invoke the shell code from the parent program by reading it into memory and typecast the starting address to a function pointer and then invoking it.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions