-
August 10th, 2009, 08:30 AM
#1
about execl function
Hi,
First time I am trying to use execl() function to execute a perl script in my c++ code. As a test I used something like this:
Code:
int main()
{
execl("/home/user/abc/test.pl", "/home/user/abc/test.pl", temp, NULL);
std::cout << "ok" << std::endl;
return 0;
}
Here, perl script display the content of the home directory, temp is just a dummy argument which I use in my actual code. execl function execute the perl script fine but the problem is the c++ code terminates after "execl()" function, i.e. it does not execute the second line "std::cout << "ok" << std::endl". No error is displayed.
Any idea how to fix this will be appreciated.
Thanks.
-
August 10th, 2009, 09:15 AM
#2
Re: about execl function
Have you read the man page of execl?
First sentence:
The exec family of functions replaces the current process image with a new process image.
Your c++ program is not executing any more. It got replaced by perl.
More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason - including blind stupidity. --W.A.Wulf
Premature optimization is the root of all evil --Donald E. Knuth
Please read Information on posting before posting, especially the info on using [code] tags.
-
August 10th, 2009, 09:27 AM
#3
Re: about execl function
Ok, Thanks a lot.
Is there any way to execute perl script within c++ code without replacing it? I tries system() but I have to give numerical argument to the perl script.
Thanks again.
-
August 11th, 2009, 05:12 AM
#4
Re: about execl function
Originally Posted by manojg
Ok, Thanks a lot.
Is there any way to execute perl script within c++ code without replacing it? I tries system() but I have to give numerical argument to the perl script.
Thanks again.
Any program that is called from the command line accepts an array of strings (char*) as argument. So the easiest way for your is to use system.
The alternative way is to first fork(), then have the child process execute execl and the parent process wait for the child (waitpid). Check for an example usage of fork if you want to walk this path.
More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason - including blind stupidity. --W.A.Wulf
Premature optimization is the root of all evil --Donald E. Knuth
Please read Information on posting before posting, especially the info on using [code] tags.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|