Is it possible to display bash shell stdout using the tailf:exec action?

I have the following yang code:

module diags {
  namespace "http://abc123.com/ns/diags";
  prefix diags;

  import tailf-common {
    prefix tailf;
  }

  container diags {
    description "Diagnostics tools and settings";
    tailf:action collect {
      description "Collect diagnostics data";
      tailf:exec "collect" {
        tailf:args "-c $(context) -p $(path)";
      }
      input {
        leaf outfile {
          type string;
          default "collect.data";
          mandatory false;
        }
      }
    }
  }
}

The contents of the collect script is as follows:

#!/bin/bash
echo "User $USER is running collect with arguments: $@"
exit 0

This all compiles and loads, but when I enter the following in confd_cli,

request diags collect

I get the following line in the CLI:
Error:
[error]

And the following line in the developer log:

<ERR> 16-Sep-2019::16:20:10.601 jonnydev-1-dev-server confd[19047]: confd osCommand error: /home/jfleming/confd/lib/confd/lib/core/confd/priv/cmdwrapper -I 127.0.0.1 -p 4565 -i 0 -m 9 -G "10,100,1001" -c L2hvbWUvamZsZW1pbmcvY29uZmQvdGVzdA== -U 12 -e -N amZsZW1pbmc= collect Jy1jJyAnY2xpJyAnLXAnICdkaWFncycgIG91dGZpbGUgJ3Frdmlldy5xa3Yn: warning: failed to set secondary groups

I would have expected to see the output of my collect script in the confd_cli session.

I’ve checked my file system, and run the sample code successfully. Am I trying to accomplish the impossible?

An action with tailf:exec should print its output parameters (if any) on stdout, see the section Action as an Executable in the User Guide - i.e. you can’t print free-form text on stdout.

This is just a warning, expected if you run ConfD as an ordinary user, and unrelated to the stdout issue. I would have expected that you got an error with “Invalid result tag from external command” though, as ConfD would have tried (and failed) to match “User” to one of the (non-existent) output parameters.

Well, you can’t do it the way you are attempting. And generally, since an action is supposed to be possible to invoke from any NB interface, generating some free-form text is not a good idea. It is doable for the CLI though, but if the functionality you are implementing really is CLI-specific, it might be better to do it as a command defined in a clispec.

You can of course check inside your action if it is invoked from the CLI, and only in that case generate some text for printing in the CLI. For an action implemented as a callback, you can (in C) use one of the maapi_cli_xxx functions, e.g. maapi_cli_write() or maapi_cli_printf() - for an action implemented as a script/executable, you can instead use the maapi command with the --msg option to do the same, see the maapi(1) manual page.

Thank you very much for your thorough and thoughtful reply! This helps immensely.