You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Stephen Ince <si...@opendemand.com> on 2009/03/11 17:08:01 UTC

exec a process.

Is there a portable way to exec a file within the apr?
I noticed that apr_proc_fork is not portable.
I basically want to do the following.

#setup stdin and stdout.
exec("/my file") in a separate process.
#wait for the process.

Steve

Re: exec a process.

Posted by Stephen Ince <si...@opendemand.com>.
I was able to get parent directory using the following. I do not know if it
is an easier way using the apr.

    PROG_NAME=argv[0];
:
    /* setup directory, use the same directory as the executing program */
    {
        int i = strlen(PROG_NAME)-1;
        dirname = apr_pstrdup(pool,PROG_NAME);
        for(; i >=0;--i){
            if(dirname[i] == '/' || dirname[i] == '\\'){
                dirname[i]='\0';
                break;
            }
        }
        if(i==0)dirname=".";
    }
:
    status = apr_procattr_dir_set(attr,dirname);
    status = apr_proc_create(&newproc, exec_path, args, NULL, attr, pool);

----- Original Message ----- 
From: "Stephen Ince" <si...@opendemand.com>
To: "APR Development" <de...@apr.apache.org>
Sent: Friday, March 13, 2009 10:34 AM
Subject: Re: exec a process.


> Relative paths do work. You have to use apr_procattr_dir_set. It is 
> relative to the calling process cwd.
> I need to set cwd directory to be the directory location of the calling 
> process.
> e.g.
> If the parent process is /openload/bin/openload.exe.
> I need to set the directory location to "/openload/bin".
> In the apr how do you get the directory of the main process?
>    status = apr_procattr_dir_set(attr,directory_location);
>
> Steve
>
>
> ----- Original Message ----- 
> From: "Stephen Ince" <si...@opendemand.com>
> To: "Eric Covener" <co...@gmail.com>; "APR Development" 
> <de...@apr.apache.org>
> Sent: Friday, March 13, 2009 9:59 AM
> Subject: Re: exec a process.
>
>
>>I just one final issue. I can't seem to get relative paths to work for 
>>apr_proc_create. Absolute path works great.
>> I have also tried using apr_filepath_root to get the canonical but I 
>> can't seem to get it work either.
>>
>> I have tried the following.
>>
>>    exec_name="openload.exe";
>>    // this fails. openload.exe is actually the program itself (it is in 
>> the same directory).  (/openload/bin/openload.exe works )
>>    exec_path="./openload.exe";
>>    args[0] = exec_name;
>>    args[1] = url->arg;
>>    args[2] = NULL;
>>    status = apr_proc_create(&newproc, exec_path, args, NULL, attr, pool);
>>
>> Is there a way for "apr_proc_create" to use relative paths for an 
>> executeable or get the canonical path for an executeable?
>> I am testing on win32. Any help would be greatly appreciated.
>>
>> Steve
>>
>> ----- Original Message ----- 
>> From: "Eric Covener" <co...@gmail.com>
>> To: "APR Development" <de...@apr.apache.org>
>> Sent: Wednesday, March 11, 2009 12:16 PM
>> Subject: Re: exec a process.
>>
>>
>>> On Wed, Mar 11, 2009 at 12:08 PM, Stephen Ince <si...@opendemand.com> 
>>> wrote:
>>>> Is there a portable way to exec a file within the apr?
>>>> I noticed that apr_proc_fork is not portable.
>>>> I basically want to do the following.
>>>>
>>>> #setup stdin and stdout.
>>>> exec("/my file") in a separate process.
>>>> #wait for the process.
>>>
>>>
>>> apr_procattr_* is available:
>>>
>>> http://svn.apache.org/viewvc/apr/apr/trunk/include/apr_thread_proc.h?view=co
>>> http://svn.apache.org/viewvc/apr/apr/trunk/test/testproc.c?view=co
>>>
>>>
>>> -- 
>>> Eric Covener
>>> covener@gmail.com
>>>
>>
>>
>
> 


Re: exec a process.

Posted by Stephen Ince <si...@opendemand.com>.
Relative paths do work. You have to use apr_procattr_dir_set. It is relative 
to the calling process cwd.
I need to set cwd directory to be the directory location of the calling 
process.
e.g.
If the parent process is /openload/bin/openload.exe.
I need to set the directory location to "/openload/bin".
In the apr how do you get the directory of the main process?
    status = apr_procattr_dir_set(attr,directory_location);

Steve


----- Original Message ----- 
From: "Stephen Ince" <si...@opendemand.com>
To: "Eric Covener" <co...@gmail.com>; "APR Development" 
<de...@apr.apache.org>
Sent: Friday, March 13, 2009 9:59 AM
Subject: Re: exec a process.


>I just one final issue. I can't seem to get relative paths to work for 
>apr_proc_create. Absolute path works great.
> I have also tried using apr_filepath_root to get the canonical but I can't 
> seem to get it work either.
>
> I have tried the following.
>
>    exec_name="openload.exe";
>    // this fails. openload.exe is actually the program itself (it is in 
> the same directory).  (/openload/bin/openload.exe works )
>    exec_path="./openload.exe";
>    args[0] = exec_name;
>    args[1] = url->arg;
>    args[2] = NULL;
>    status = apr_proc_create(&newproc, exec_path, args, NULL, attr, pool);
>
> Is there a way for "apr_proc_create" to use relative paths for an 
> executeable or get the canonical path for an executeable?
> I am testing on win32. Any help would be greatly appreciated.
>
> Steve
>
> ----- Original Message ----- 
> From: "Eric Covener" <co...@gmail.com>
> To: "APR Development" <de...@apr.apache.org>
> Sent: Wednesday, March 11, 2009 12:16 PM
> Subject: Re: exec a process.
>
>
>> On Wed, Mar 11, 2009 at 12:08 PM, Stephen Ince <si...@opendemand.com> 
>> wrote:
>>> Is there a portable way to exec a file within the apr?
>>> I noticed that apr_proc_fork is not portable.
>>> I basically want to do the following.
>>>
>>> #setup stdin and stdout.
>>> exec("/my file") in a separate process.
>>> #wait for the process.
>>
>>
>> apr_procattr_* is available:
>>
>> http://svn.apache.org/viewvc/apr/apr/trunk/include/apr_thread_proc.h?view=co
>> http://svn.apache.org/viewvc/apr/apr/trunk/test/testproc.c?view=co
>>
>>
>> -- 
>> Eric Covener
>> covener@gmail.com
>>
>
> 


Re: exec a process.

Posted by Stephen Ince <si...@opendemand.com>.
I just one final issue. I can't seem to get relative paths to work for 
apr_proc_create. Absolute path works great.
I have also tried using apr_filepath_root to get the canonical but I can't 
seem to get it work either.

I have tried the following.

    exec_name="openload.exe";
    // this fails. openload.exe is actually the program itself (it is in the 
same directory).  (/openload/bin/openload.exe works )
    exec_path="./openload.exe";
    args[0] = exec_name;
    args[1] = url->arg;
    args[2] = NULL;
    status = apr_proc_create(&newproc, exec_path, args, NULL, attr, pool);

Is there a way for "apr_proc_create" to use relative paths for an 
executeable or get the canonical path for an executeable?
I am testing on win32. Any help would be greatly appreciated.

Steve

----- Original Message ----- 
From: "Eric Covener" <co...@gmail.com>
To: "APR Development" <de...@apr.apache.org>
Sent: Wednesday, March 11, 2009 12:16 PM
Subject: Re: exec a process.


> On Wed, Mar 11, 2009 at 12:08 PM, Stephen Ince <si...@opendemand.com> 
> wrote:
>> Is there a portable way to exec a file within the apr?
>> I noticed that apr_proc_fork is not portable.
>> I basically want to do the following.
>>
>> #setup stdin and stdout.
>> exec("/my file") in a separate process.
>> #wait for the process.
>
>
> apr_procattr_* is available:
>
> http://svn.apache.org/viewvc/apr/apr/trunk/include/apr_thread_proc.h?view=co
> http://svn.apache.org/viewvc/apr/apr/trunk/test/testproc.c?view=co
>
>
> -- 
> Eric Covener
> covener@gmail.com
> 


Re: exec a process.

Posted by Branko Čibej <br...@xbc.nu>.
Daniel.Pocock@barclayscapital.com wrote:
>>> Is there a portable way to exec a file within the apr?
>>> I noticed that apr_proc_fork is not portable.
>>> I basically want to do the following.
>>>
>>> #setup stdin and stdout.
>>> exec("/my file") in a separate process.
>>> #wait for the process.
>>>       
>> apr_procattr_* is available:
>>     
>
> Can this be used to simulate the behaviour of execve in a portable way?
>   

If you try reading the APR docs, then yes.

> _______________________________________________
>
> This e-mail may contain information that is confidential, privileged or otherwise protected from disclosure. If you are not an intended recipient of this e-mail, do not duplicate or redistribute it by any means. Please delete it and any attachments and notify the sender that you have received it in error. Unless specifically indicated, this e-mail is not an offer to buy or sell or a solicitation to buy or sell any securities, investment products or other financial product or service, an official confirmation of any transaction, or an official statement of Barclays. Any views or opinions presented are solely those of the author and do not necessarily represent those of Barclays. This e-mail is subject to terms available at the following link: www.barcap.com/emaildisclaimer. By messaging with Barclays you consent to the foregoing.  Barclays Capital is the investment banking division of Barclays Bank PLC, a company registered in England (number 1026167) with its registered office at 1 Churchill Place, London, E14 5HP.  This email may relate to or be sent from other members of the Barclays Group.
> _______________________________________________
>   

But I must assume the docs are too confidential for you.

-- Brane


RE: exec a process.

Posted by Da...@barclayscapital.com.
> > Is there a portable way to exec a file within the apr?
> > I noticed that apr_proc_fork is not portable.
> > I basically want to do the following.
> >
> > #setup stdin and stdout.
> > exec("/my file") in a separate process.
> > #wait for the process.
> 
> 
> apr_procattr_* is available:

Can this be used to simulate the behaviour of execve in a portable way?
_______________________________________________

This e-mail may contain information that is confidential, privileged or otherwise protected from disclosure. If you are not an intended recipient of this e-mail, do not duplicate or redistribute it by any means. Please delete it and any attachments and notify the sender that you have received it in error. Unless specifically indicated, this e-mail is not an offer to buy or sell or a solicitation to buy or sell any securities, investment products or other financial product or service, an official confirmation of any transaction, or an official statement of Barclays. Any views or opinions presented are solely those of the author and do not necessarily represent those of Barclays. This e-mail is subject to terms available at the following link: www.barcap.com/emaildisclaimer. By messaging with Barclays you consent to the foregoing.  Barclays Capital is the investment banking division of Barclays Bank PLC, a company registered in England (number 1026167) with its registered office at 1 Churchill Place, London, E14 5HP.  This email may relate to or be sent from other members of the Barclays Group.
_______________________________________________

Re: exec a process.

Posted by Eric Covener <co...@gmail.com>.
On Wed, Mar 11, 2009 at 12:08 PM, Stephen Ince <si...@opendemand.com> wrote:
> Is there a portable way to exec a file within the apr?
> I noticed that apr_proc_fork is not portable.
> I basically want to do the following.
>
> #setup stdin and stdout.
> exec("/my file") in a separate process.
> #wait for the process.


apr_procattr_* is available:

http://svn.apache.org/viewvc/apr/apr/trunk/include/apr_thread_proc.h?view=co
http://svn.apache.org/viewvc/apr/apr/trunk/test/testproc.c?view=co


-- 
Eric Covener
covener@gmail.com