How to run C++ program

Im not sure what to do here so i thought i would ask.

I have this C++ program installed and working on my Rasp pi3

In CP i can run
$ sunsaver

then i input the option i want 1-5 to give me the output i want.

$ 5

My question is how do i configure the exec node to input the number option 1-5?

My second question is, is this the best way to do it the C++ also has a "Save output" command
$ ./sunsaver > output/snapshot_$(date +%Y-%m-%d_%H-%M-%S)`

then options 1-5

or
$ ./sunsaver > output/logs_$(date +%Y-%m-%d_%H-%M-%S)`

then options 1-5

At the moment i would like to start with reading battery voltage and maybe create a dashboard.
Any help or ideas gratefully recieved.

welcome to the forum @picklerick

After entering 5 does the program close or does it go back to waiting for input?

Hi @picklerick.

This is not really a feature of the C program, it justs prints it's output to the "standard output" device. the > .node-red/node_modules/node-red-dashboard/dist/js is using the Bash shell to redirect the output into a file.
This is a good thing for you, the program output will magically appear in msg.payload after the exec node.

It is possible that the program is designed to accept the option 1-5 from the command line, eg
sunsaver 5.

If not, the simplest solution (unless someone else knows how to do a "Here Document" from exec) is to write a script "callsunsaver" to call the program, something like this

#! /bin/bash
/full/path/to/sunsaver <<EOF
$1
EOF

Make callsunsaver executable chmod +x callsunsaver

Now your exec node would be something like this

[
    {
        "id": "3f1453d2073c0cbe",
        "type": "inject",
        "z": "03f8230b250f8d2a",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "2",
        "payloadType": "str",
        "x": 290,
        "y": 140,
        "wires": [
            [
                "772114dbc4e4519d"
            ]
        ]
    },
    {
        "id": "772114dbc4e4519d",
        "type": "exec",
        "z": "03f8230b250f8d2a",
        "command": "/home/pi/bin/callsunsaver",
        "addpay": "payload",
        "append": "",
        "useSpawn": "false",
        "timer": "",
        "winHide": false,
        "oldrc": false,
        "name": "",
        "x": 510,
        "y": 160,
        "wires": [
            [
                "98678fcdfeebb11d"
            ],
            [],
            []
        ]
    },
    {
        "id": "98678fcdfeebb11d",
        "type": "debug",
        "z": "03f8230b250f8d2a",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 750,
        "y": 160,
        "wires": []
    },
    {
        "id": "efdb7dfcb07f689a",
        "type": "inject",
        "z": "03f8230b250f8d2a",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "5",
        "payloadType": "str",
        "x": 290,
        "y": 180,
        "wires": [
            [
                "772114dbc4e4519d"
            ]
        ]
    }
]

As @Colin hints, if sunsaver waits for more input it's going to be a problem.

sunsaver runs the program then after entering a number 1 to 5 it returns the data chosen then closes.

Thats great thank you it worked a treat,

I think you should also be able to do, in the exec node
echo "5" | /full/path/to/sunsaver
Try it in a terminal first.

Yes that works from terminal, so to run in node-red i would then input that code into the exec node?
thank you for your help,

Yes, doesn't it work?

yes that works, thank you,

now i got to do something with this data.