apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stephen Ince" <si...@opendemand.com>
Subject Re: exec a process.
Date Fri, 13 Mar 2009 19:16:45 GMT
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" <since@opendemand.com>
To: "APR Development" <dev@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" <since@opendemand.com>
> To: "Eric Covener" <covener@gmail.com>; "APR Development" 
> <dev@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" <covener@gmail.com>
>> To: "APR Development" <dev@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 <since@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
>>>
>>
>>
>
> 


Mime
View raw message