calling a shell script from exec.
Hi ,
I was trying to use exec to run a shell script #include<stdio.h> #include<unistd.h> int main(int argc,char *argv[]) { unsigned int child; switch(child=fork()) { case 0: printf("in child"); execv("./check_script",NULL); break; case -1: printf("Error"); break; default: printf("Parent %d",child); break; } return 0; } However on executing the above code , I am getting the following output. /a.out Parent 17507in child check_script just echoes a String . Please explain this behaviour. |
Can you share the contents of your check_script?
|
Hi,
It just echoes iniside script. vi ./check_script echo "Inside script" Thanks.. |
Please use [CODE] [/CODE] tags around your code, to make it readable.
Quote:
I often use something like Code:
char *args[2] = { "./check_script", NULL }; Code:
execl("./check_script", "./check_script", NULL); Just remember that the path to the script is first, then the script name -- in both argument array and execl() parameter list --, followed by parameters, followed by NULL, and that neither the path to the script nor the script name can be NULL. The second part of your problem is that you are missing the shebang line, which tells the kernel which shell interpreter to use: Code:
#!/bin/bash |
Thanks for help ...
|
All times are GMT -5. The time now is 02:07 AM. |