Passing arguments when starting a snap from a snap does not seem to be possible

Hello there !

We have a first program mysnap.launcher who is lauching my other with the current command (in a cpp code) :

int errCode = system(“snapctl start”);

This works like a charm, and we are quite happy about it :slight_smile:

But now we want to do add an argument

int errCode = system(“snapctl start --my-option”);

This does not work, is passing an arg when starting a snap supported ?

Btw is there somewhere with a snapctl doc? snapctl -h does not have much options, we found somewhere on internet that we could do something like

snapctl run --my-option

And it works, but does seem to be run in the current shell launched and not handled by the “snap management” layer

Any hints about this ? Or are we missing something? Is there a better solution to simply pass an arg when launching a snap from a snap ?


This is starting a daemon in your snap, not running the snap app process from inside your snap. You can run a specific snap app from the current snap by just executing the appropriate binary or shell script referenced in the snapcraft.yaml for your snap’s app.

The reason this does not work is because you aren’t launching an app, you are asking systemd (eventually via systemctl) to start the daemon. That daemon runs with whatever args are defined in the snapcraft.yaml for your snap and as such doesn’t allow changing the arguments this way.

This will not work, snapctl does not support run, see:

$ snapctl run my-snap
error: error running snapctl: Unknown command `run'. Please specify one command of: get, restart, services, set, set-health, start, stop or unset

Perhaps you are thinking of running snap apps via snap run my-snap ..., which only works outside of snap confinement. A snap is not allowed to launch other snaps or even use the snap command, things that you would normally use snap to do that you want to do in the snap should be done with snapctl, but note that some things are still disallowed from inside the snap (such as the snap run command).

There is some information on but we could use more information on snapctl considering it has grown considerably beyond just accessing snap config.

Yes that’s actually exactly what we want to do, we were trying to check if there was a way to provide an arg to this daemon or not. Thanks for confirming that it is indeed impossible, we will find another way !

And thanks for the quick reply ! :wink:

One way that you could do this is to have your program read options from snapctl, so instead of doing something like

./program --my-option

inside the code for program you would call snapctl get like this:

snapctl get my-option

and when you want to change that option just call snapctl set my-option=true or something like that.

Oh yes, that’s a nice workaround, will explore that, thanks a lot !