[MAC] Launching OO from another application using OSL_executeprocess

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

[MAC] Launching OO from another application using OSL_executeprocess

Anandha Kannan
Hello there,

     Am trying to automate open office from my application developing for
MAC. Am using OO SDK 3.4.1 in Mac OSX 10.7.4. When i want to launch OO from
my application using osl/process.h: [b]osl_executeProcess[/b] using the
following code, I get error osl_Process_E_Unknown. OSL_executeprocess can
be used in Mac? Does it work for anyone to launch OO process on Mac. Any
guidance/help would be greatly appreciated.


        *.......*
*        .......*
*        OUString appExe = OUString::createFromAscii("open -a
/Applications/OpenOffice.org.app/Contents/MacOS/scalc"); *
*        OUString FileURL;*
*        if(osl::FileBase::getFileURLFromSystemPath(appExe, FileURL) !=
osl::FileBase::E_None)*
*        {*
*            cout << "Cannot Convert Application Path to URL" << endl;*
*        }*
*      OUString AppArgs =
OUString::createFromAscii("/Volumes/data/test.ods");*
*      oslProcessError osl_error = osl_executeProcess(FileURL.pData,
&AppArgs.pData,  1, osl_Process_DETACHED, 0, NULL,  NULL, 0, &rProcess );*
*      switch ( osl_error )*
*                {*
*                        case osl_Process_E_None:*
*                            osl_freeProcessHandle( rProcess );*
*                            printf("\n Execute process Succeeded with
E_NONE");*
*                            break;*
*                        case osl_Process_E_NotFound:*
*                            osl_freeProcessHandle( rProcess );*
*                            printf("\n Execute process failed with
E_NotFound");*
*                            break;*
*                        case osl_Process_E_TimedOut:*
*                            osl_freeProcessHandle( rProcess );*
*                            printf("\n Execute process failed with
E_TimedOut");*
*                            break;*
*                        case osl_Process_E_NoPermission:*
*                            osl_freeProcessHandle( rProcess );*
*                            printf("\n Execute process failed with
E_NoPermission");*
*                            break;*
*                        case osl_Process_E_Unknown:*
*                            osl_freeProcessHandle( rProcess );*
*                            printf("\n Execute process failed with
E_Unknown");*
*                            break;*
*                        case osl_Process_E_InvalidError:*
*                            osl_freeProcessHandle( rProcess );*
*                            printf("\n Execute process failed with
E_InvalidError");*
*                            break;*
*                        default:*
*                           printf("unmapped error!\n");*
*                 }*
*
*
*         ..........*
*         ..........*


 I also have tried to launch OO using Terminal application as shown below,
and i end up getting with the same error.


       *OUString appExe         = OUString::createFromAscii(
"/Applications/Utilities/Terminal.app");*
*       OUString FileURL;*
*        if(osl::FileBase::getFileURLFromSystemPath(appExe, FileURL) !=
osl::FileBase::E_None)*
*        {*
*            cout << "Cannot Convert Application Path to URL" << endl;*
*        }*
*      OUString AppArgs = OUString::createFromAscii("open
/Applications/OpenOffice.org.app/Contents/MacOS/scalc
/Volumes/data/kannana/TestLib/test.ods");*
*      oslProcessError osl_error = osl_executeProcess(FileURL.pData,
&AppArgs.pData,  1, osl_Process_DETACHED, 0, NULL,  NULL, 0, &rProcess );*
*      ...........*
*      ...........*


I can launch OO from terminal using "open". But it fails when i pass it to
osl method to launch the process..

Thanks in Advance / Anandh
Reply | Threaded
Open this post in threaded view
|

Re: [MAC] Launching OO from another application using OSL_executeprocess

Ariel Constenla-Haile-2
Hi,

On Tue, Feb 19, 2013 at 02:02:25PM +0530, Anandha Kannan wrote:

> Hello there,
>
>      Am trying to automate open office from my application developing for
> MAC. Am using OO SDK 3.4.1 in Mac OSX 10.7.4. When i want to launch OO from
> my application using osl/process.h: [b]osl_executeProcess[/b] using the
> following code, I get error osl_Process_E_Unknown. OSL_executeprocess can
> be used in Mac? Does it work for anyone to launch OO process on Mac. Any
> guidance/help would be greatly appreciated.
>
>
>         *.......*
> *        .......*
> *        OUString appExe = OUString::createFromAscii("open -a
> /Applications/OpenOffice.org.app/Contents/MacOS/scalc"); *
> *        OUString FileURL;*
> *        if(osl::FileBase::getFileURLFromSystemPath(appExe, FileURL) !=
> osl::FileBase::E_None)*
> *        {*
> *            cout << "Cannot Convert Application Path to URL" << endl;*
> *        }*
> *      OUString AppArgs =
> OUString::createFromAscii("/Volumes/data/test.ods");*
> *      oslProcessError osl_error = osl_executeProcess(FileURL.pData,
> &AppArgs.pData,  1, osl_Process_DETACHED, 0, NULL,  NULL, 0, &rProcess );*
If the command you execute in the command line is

open -a /Applications/OpenOffice.org.app/Contents/MacOS/scalc /Volumes/data/test.ods


Then "<path_to>/open" should be the first parameter; "-a",
"/Applications/OpenOffice.org.app/Contents/MacOS/scalc" and
"/Volumes/data/test.ods" shouold be in the array of the second
parameter, and the third, the arguments count, is 3.

That said, it seems there is no need to use "open -a" with
osl_executeProcess, on MacOS, this example compiles and runs fine
(run make with PRJ=$OO_SDK_HOME):
http://svn.apache.org/viewvc/openoffice/devtools/sdk-examples/trunk/cpp/ProcessTest/

You can check the examples with subversion:

svn co https://svn.apache.org/repos/asf/openoffice/sdk-examples/trunk sdk-examples


Regards
--
Ariel Constenla-Haile
La Plata, Argentina

attachment0 (853 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [MAC] Launching OO from another application using OSL_executeprocess

Anandha Kannan
Hi Ariel,



                Thanks for the response. This helped me to correct few of
my mistakes I had done.

having modified my code, now after calling osl_executeprocess, my
application tries to launch OO and executeProcess returns E_None, but OO
quits and with,

"The application cannot be started.The component manager is not available."

Some pages says, possible corrupt of services.rdb in OO installation. But
am not sure what is causing this issue.

Any help please?



Thanks,

Anandh


On Tue, Feb 19, 2013 at 8:33 PM, Ariel Constenla-Haile
<[hidden email]>wrote:

> Hi,
>
> On Tue, Feb 19, 2013 at 02:02:25PM +0530, Anandha Kannan wrote:
> > Hello there,
> >
> >      Am trying to automate open office from my application developing for
> > MAC. Am using OO SDK 3.4.1 in Mac OSX 10.7.4. When i want to launch OO
> from
> > my application using osl/process.h: [b]osl_executeProcess[/b] using the
> > following code, I get error osl_Process_E_Unknown. OSL_executeprocess can
> > be used in Mac? Does it work for anyone to launch OO process on Mac. Any
> > guidance/help would be greatly appreciated.
> >
> >
> >         *.......*
> > *        .......*
> > *        OUString appExe = OUString::createFromAscii("open -a
> > /Applications/OpenOffice.org.app/Contents/MacOS/scalc"); *
> > *        OUString FileURL;*
> > *        if(osl::FileBase::getFileURLFromSystemPath(appExe, FileURL) !=
> > osl::FileBase::E_None)*
> > *        {*
> > *            cout << "Cannot Convert Application Path to URL" << endl;*
> > *        }*
> > *      OUString AppArgs =
> > OUString::createFromAscii("/Volumes/data/test.ods");*
> > *      oslProcessError osl_error = osl_executeProcess(FileURL.pData,
> > &AppArgs.pData,  1, osl_Process_DETACHED, 0, NULL,  NULL, 0, &rProcess
> );*
>
> If the command you execute in the command line is
>
> open -a /Applications/OpenOffice.org.app/Contents/MacOS/scalc
> /Volumes/data/test.ods
>
>
> Then "<path_to>/open" should be the first parameter; "-a",
> "/Applications/OpenOffice.org.app/Contents/MacOS/scalc" and
> "/Volumes/data/test.ods" shouold be in the array of the second
> parameter, and the third, the arguments count, is 3.
>
> That said, it seems there is no need to use "open -a" with
> osl_executeProcess, on MacOS, this example compiles and runs fine
> (run make with PRJ=$OO_SDK_HOME):
>
> http://svn.apache.org/viewvc/openoffice/devtools/sdk-examples/trunk/cpp/ProcessTest/
>
> You can check the examples with subversion:
>
> svn co https://svn.apache.org/repos/asf/openoffice/sdk-examples/trunksdk-examples
>
>
> Regards
> --
> Ariel Constenla-Haile
> La Plata, Argentina
>
Reply | Threaded
Open this post in threaded view
|

Re: [MAC] Launching OO from another application using OSL_executeprocess

Ariel Constenla-Haile-2
Hi Anandha,

On Thu, Feb 21, 2013 at 02:28:19PM +0530, Anandha Kannan wrote:

> Hi Ariel,
>
>
>
>                 Thanks for the response. This helped me to correct few of
> my mistakes I had done.
>
> having modified my code, now after calling osl_executeprocess, my
> application tries to launch OO and executeProcess returns E_None, but OO
> quits and with,
>
> "The application cannot be started.The component manager is not available."
>
> Some pages says, possible corrupt of services.rdb in OO installation. But
> am not sure what is causing this issue.
 
That error is produced because the application cannot bootstrap the
initial component context (similar to an external application when it
bootstraps the initial component context with the URE types); the error
message is too generic as to get an idea where the problem is (a broken
ini/rc file, broken registry database, essential libraries that cannot
be loaded - bootstrap.uno.so etc., ...).

If you are able to launch OpenOffice from the terminal, you should be
able to use osl_executeProcess(), this seems something logical. How are
you running the application that uses osl_executeProcess()? Which is the
current directory? Are you running as root or as normal user? Note that
in the example, both user+rights and working directory are NULL, which
will default to osl_getCurrentSecurity() and osl_getProcessWorkingDir(),
all of which is fine if you are running the application as a normal
user.

And finally, does the example [1] work?
[1] http://svn.apache.org/viewvc/openoffice/devtools/sdk-examples/trunk/cpp/ProcessTest/


Regards
--
Ariel Constenla-Haile
La Plata, Argentina

attachment0 (853 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [MAC] Launching OO from another application using OSL_executeprocess

Anandha Kannan
Hi Ariel,

    Thanks for the quick reply. To answer your questions..

 + I am able to launch open office from Terminal without any issues. But
not from my application.
 + My application is linked with a library myoocalc.dylib (from which
osl_executeprocess is being called.) and libuni_ccpu.dylib.3,
libuno_cppuhelpergcc3.dylib.3, libuno_sal.dylilb.3, etc..
    ++ The all dynamic libraries are located at
/Volumes/data/OpenOffice.org_SDK/OpenOffice.org_SDK/MACOSXexample.out/lib
    ++ My application calls a myoocalc.dylib's method which calls
osl_executeprocess method
 + Am running my application as root user.
 + The sample code u sent works fine..

Am not sure whether i'm doing anything incorrect here with linking my
application with dylib which invokes OO.

Thanks in advance for your help,
Anandh

On Thu, Feb 21, 2013 at 3:28 PM, Ariel Constenla-Haile
<[hidden email]>wrote:

> Hi Anandha,
>
> On Thu, Feb 21, 2013 at 02:28:19PM +0530, Anandha Kannan wrote:
> > Hi Ariel,
> >
> >
> >
> >                 Thanks for the response. This helped me to correct few of
> > my mistakes I had done.
> >
> > having modified my code, now after calling osl_executeprocess, my
> > application tries to launch OO and executeProcess returns E_None, but OO
> > quits and with,
> >
> > "The application cannot be started.The component manager is not
> available."
> >
> > Some pages says, possible corrupt of services.rdb in OO installation. But
> > am not sure what is causing this issue.
>
> That error is produced because the application cannot bootstrap the
> initial component context (similar to an external application when it
> bootstraps the initial component context with the URE types); the error
> message is too generic as to get an idea where the problem is (a broken
> ini/rc file, broken registry database, essential libraries that cannot
> be loaded - bootstrap.uno.so etc., ...).
>
> If you are able to launch OpenOffice from the terminal, you should be
> able to use osl_executeProcess(), this seems something logical. How are
> you running the application that uses osl_executeProcess()? Which is the
> current directory? Are you running as root or as normal user? Note that
> in the example, both user+rights and working directory are NULL, which
> will default to osl_getCurrentSecurity() and osl_getProcessWorkingDir(),
> all of which is fine if you are running the application as a normal
> user.
>
> And finally, does the example [1] work?
> [1]
> http://svn.apache.org/viewvc/openoffice/devtools/sdk-examples/trunk/cpp/ProcessTest/
>
>
> Regards
> --
> Ariel Constenla-Haile
> La Plata, Argentina
>
Reply | Threaded
Open this post in threaded view
|

Re: [MAC] Launching OO from another application using OSL_executeprocess

Ariel Constenla-Haile-2
Hi Anandha,

On Thu, Feb 21, 2013 at 04:49:26PM +0530, Anandha Kannan wrote:

> Hi Ariel,
>
>     Thanks for the quick reply. To answer your questions..
>
>  + I am able to launch open office from Terminal without any issues. But
> not from my application.
>  + My application is linked with a library myoocalc.dylib (from which
> osl_executeprocess is being called.) and libuni_ccpu.dylib.3,
> libuno_cppuhelpergcc3.dylib.3, libuno_sal.dylilb.3, etc..
>     ++ The all dynamic libraries are located at
> /Volumes/data/OpenOffice.org_SDK/OpenOffice.org_SDK/MACOSXexample.out/lib
>     ++ My application calls a myoocalc.dylib's method which calls
> osl_executeprocess method
>  + Am running my application as root user.
This might be the root of the problem.

>  + The sample code u sent works fine..

Did you run the example as root, too?

> Am not sure whether i'm doing anything incorrect here with linking my
> application with dylib which invokes OO.

When you develop a C++ client application, the application is launched
indirectly, through the unoapploader:

- your application binary is renamed to _<yourapp>
- the unoapploader from the SDK is copied aside your application and
  renamed <yourapp>

The UNO application loader detects a UNO installation on the system and
adds some variables to the environment, see the comment in
http://opengrok.adfinis-sygroup.org/source/xref/aoo-trunk/main/odk/source/unoapploader/unx/unoapploader.c

Your library is linked to the URE libraries, but your executable not;
this is right, if the executable in itself does not need linking to
them. But how are you executing your executable? Directly, or through
the UNO application loader?

If you are not using the unoapploader, try it and see if it fixes the
problem (take the unoapploader from the SDK instalation and copy it in
the same directory where your executable is; rename your executable,
adding an underscore at the beginning, and rename the unoapploader with
the original name of your application).

If you want to avoid using the UNO application loader, you can set the
environment in the call to osl_executeProcess(), it has two parameters:
ustrEnviroments and nEnvironmentVars (I'd point you to the online
documentation, but there is a bug in autodoc, and the doc for
/sdk/include/osl/process.h is not generated
http://www.openoffice.org/api/docs/cpp/ref/names/o-process.h.html#osl_executeProcess-752).


Regards
--
Ariel Constenla-Haile
La Plata, Argentina

attachment0 (853 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [MAC] Launching OO from another application using OSL_executeprocess

Anandha Kannan
Hi Ariel,

     This is really worth a lot of information for me.. Thanks to you for
the valuable information. I ran the processtest sample also as a root user.

My C++ client application using Xcode, and I was running the client
application directly, I didn't use unoapploader before.
But if i use unoapploader (as the way u suggested ), and while Running
VerificationOO from terminal (where setsdkenv_unix had run already), OO
launches. :) This is good news for me. But I couldn't run/debug the
application from Xcode - I may need to check how to setting URE libs from
my client application.

     So, running the client application in using unoapploader solves the
issue now. But actually, i guess i need to use with ustrEnviroments and
nEnvironmentVars otherwise. Am i right?

Thanks for the guidance,
Anandh


On Thu, Feb 21, 2013 at 6:32 PM, Ariel Constenla-Haile
<[hidden email]>wrote:

> Hi Anandha,
>
> On Thu, Feb 21, 2013 at 04:49:26PM +0530, Anandha Kannan wrote:
> > Hi Ariel,
> >
> >     Thanks for the quick reply. To answer your questions..
> >
> >  + I am able to launch open office from Terminal without any issues. But
> > not from my application.
> >  + My application is linked with a library myoocalc.dylib (from which
> > osl_executeprocess is being called.) and libuni_ccpu.dylib.3,
> > libuno_cppuhelpergcc3.dylib.3, libuno_sal.dylilb.3, etc..
> >     ++ The all dynamic libraries are located at
> > /Volumes/data/OpenOffice.org_SDK/OpenOffice.org_SDK/MACOSXexample.out/lib
> >     ++ My application calls a myoocalc.dylib's method which calls
> > osl_executeprocess method
> >  + Am running my application as root user.
>
> This might be the root of the problem.
>
> >  + The sample code u sent works fine..
>
> Did you run the example as root, too?
>
> > Am not sure whether i'm doing anything incorrect here with linking my
> > application with dylib which invokes OO.
>
> When you develop a C++ client application, the application is launched
> indirectly, through the unoapploader:
>
> - your application binary is renamed to _<yourapp>
> - the unoapploader from the SDK is copied aside your application and
>   renamed <yourapp>
>
> The UNO application loader detects a UNO installation on the system and
> adds some variables to the environment, see the comment in
>
> http://opengrok.adfinis-sygroup.org/source/xref/aoo-trunk/main/odk/source/unoapploader/unx/unoapploader.c
>
> Your library is linked to the URE libraries, but your executable not;
> this is right, if the executable in itself does not need linking to
> them. But how are you executing your executable? Directly, or through
> the UNO application loader?
>
> If you are not using the unoapploader, try it and see if it fixes the
> problem (take the unoapploader from the SDK instalation and copy it in
> the same directory where your executable is; rename your executable,
> adding an underscore at the beginning, and rename the unoapploader with
> the original name of your application).
>
> If you want to avoid using the UNO application loader, you can set the
> environment in the call to osl_executeProcess(), it has two parameters:
> ustrEnviroments and nEnvironmentVars (I'd point you to the online
> documentation, but there is a bug in autodoc, and the doc for
> /sdk/include/osl/process.h is not generated
>
> http://www.openoffice.org/api/docs/cpp/ref/names/o-process.h.html#osl_executeProcess-752
> ).
>
>
> Regards
> --
> Ariel Constenla-Haile
> La Plata, Argentina
>
Reply | Threaded
Open this post in threaded view
|

Re: [MAC] Launching OO from another application using OSL_executeprocess

Ariel Constenla-Haile-2
Hi Anandh,

On Thu, Feb 21, 2013 at 09:49:01PM +0530, Anandha Kannan wrote:

> Hi Ariel,
>
>      This is really worth a lot of information for me.. Thanks to you for
> the valuable information. I ran the processtest sample also as a root user.
>
> My C++ client application using Xcode, and I was running the client
> application directly, I didn't use unoapploader before.
> But if i use unoapploader (as the way u suggested ), and while Running
> VerificationOO from terminal (where setsdkenv_unix had run already), OO
> launches. :) This is good news for me. But I couldn't run/debug the
> application from Xcode - I may need to check how to setting URE libs from
> my client application.
>
>      So, running the client application in using unoapploader solves the
> issue now. But actually, i guess i need to use with ustrEnviroments and
> nEnvironmentVars otherwise. Am i right?
yes, if you want to get rid of unoapploader, and use hard-coded values
instead,  try setting the environment: prepend to the value of
DYLD_LIBRARY_PATH the output of <office-program-path>/unoinfo c++

See the code in
http://opengrok.adfinis-sygroup.org/source/xref/aoo-trunk/main/odk/source/unoapploader/unx/unoapploader.c

It should be a single env. var.:

"DYLD_LIBRARY_PATH=<output of office-inst/program/unoinfo c++>[:value of getenv("DYLD_LIBRARY_PATH")]"


Regards
--
Ariel Constenla-Haile
La Plata, Argentina

attachment0 (853 bytes) Download Attachment