Run a command-line app from within another app



A similar question has been asked here before but it’s not clear if it was ever resolved. I followed some of the information there but couldn’t get it to work.

I’ve written my own command-line tool and would like to know how I can run it from another app.
I created a system, defined my own command and my tool runs as expected from a terminal.

My end goal here is to be able to invoke my command-line tool remotely via SMS.

The apps are running unsandboxed for the moment to make things easier.

Here’s what I’ve added to the .adef for the app wanting to run my tool.

     	/legato/systems/current/apps/myTool/read-only/bin/mytool /usr/bin/mytool
        /legato/systems/current/apps/myTool/read-only/lib/ /user/lib/
        /legato/systems/current/bin /legato/systems/current/
        /legato/systems/current/lib /legato/systems/current/

Within the app ‘runner’ I’ve tried using popen("mytool -h", "r") but the command always returns not found.
I’ve also tried including paths before the command, I.E., "/usr/bin/mytool -h" without any success.

Worth noting that I’ve been able to run the command-line tool process/component by another process/component, but only if the executables are part of the same application. This is my fall-back solution.

I’d prefer to run them as separate apps.

  1. Is this possible?

  2. If so, how can I do this?

Thanks in advance,


I think it’s probably possible to invoke the command line program from within another app, but there is probably a better option. What I would do is structure the command line app in two components:

  1. The core implementation of the features of the command line app
  2. command line argument processing, passing the data to the lower level component and printing the results.

This way you can bind your app directly to the low level component and call functions rather than trying to call a command line program and parse the string output.


Thanks for the suggestion @dfrey.

My motivation for re-using the CLI app was to take advantage of the Command Line Arguments API and use the same syntax for SMS commands. Responses would be redirected according to source of the command.

Reading through the api docs it seems like I might be able to do this by creating a pseudo-main which could serve as the command argument processor by using le_arg_SetArgs. I would then build up the arg array and pass that to my “main”. Unfortunately, I get a build error “undefined reference to `le_arg_SetArgs’”

Is there a library, header file (besides legato.h) or something I need to bind?