CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2005
    Posts
    55

    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.

  2. #2
    Join Date
    Jan 2004
    Location
    Düsseldorf, Germany
    Posts
    2,401

    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.

  3. #3
    Join Date
    Mar 2005
    Posts
    55

    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.

  4. #4
    Join Date
    Jan 2004
    Location
    Düsseldorf, Germany
    Posts
    2,401

    Re: about execl function

    Quote Originally Posted by manojg View Post
    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
  •  





Click Here to Expand Forum to Full Width

Featured