Displaying the results of system command

I have a couple of System Commands that I have added in config.yaml. They work but I would like it if the feedback I see when I run them manually was something displayed in OctoPrint. Is it possible to for these results to be displayed in a pop-up after the command is run? Or is it possible to run a System Command from the Control tab? It looked like it was gcode only.
I am not looking for someone to program it for me. I can do that. I just have been reading the current documentation and have not found something that says it is doable.

thanks in advance,

I often use the Gcode Systems Commands plugin to create pseudo-GCODEs which then run command line programs or scripts. It's easy then to add custom buttons on the Control tab.

The M117 command as combined with one of the M117 popup plugins in theory is the way to be notified of the result. You'd need something to inject that, though.

The Gcode Systems Commands plugin appears to use this technique behind-the-scenes:

r = os.system(cmd_line)

This won't return the output to anywhere, just the integer return code.

If you're a coder, you might consider forking that plugin and adjusting it for your own needs.

Alternately, you could create individual bash scripts which log the output somewhere. And then you'd need some method of displaying that log.

Thank You! for the suggestion. I will look into it. "Gcode Systems Commands" plugin? I never seen saw that one. Actually, I probably saw that it was gcode related and skipped it.

I do have another concern with using the Controls tab. One of the things I am looking at doing is controlling the power to the Printer. It has to be off before I can do some of the other system commands I need to do. I know I can control that. But if the printer is off that means the controls tab is off and that means that I can't do what I need to do in the controls tab. I am hesitant about putting together my own tab but it looks like that is where I might be going.

Thanks Again,

Ugh, is it? The Control tab on mine displays regardless of the state of the printer controller itself.

All the controls on my control tab are disabled right now. When I connect to the printer they become active. I would guess that's because they are all gcode related and without a connection to the printer they normally have a printer to work on. Maybe there is a way to toggle them on and off or better yet, toggle some of them on or off. I really want my controls only to work when the printer is off.

I should note the sliders are "active" but the rest is disabled.

Add a custom control and see if that's also the case.

Working on that right now. Thanks again.

If it doesn't allow that, then you're back to the System menu.

WOW, adding those controls was SO easy.
But they are disabled. Now I get to look for some way to enable them when the printer isn't connected.

Using "enabled: true" worked to enable the controls.
But the command line i use with parameters doesn't work. I need to put my command and parameters into a script and use that. But this is looking good.

If your script requires sudo then you'll need to permission the pi user's ability to do password-less sudo using a file in /etc/sudoers.d.

thanks - I already set that up. Actually, I bricked one SD card the other day by messing up the parameters of the sudoers.d file. Fortunately, I had just backed it up so it was just some time lost.

Well, the controls that start the scripts aren't working. They are enabled but since they launch Gcodes I don't think they will work except when the printer is connected. Since it's not, the terminal window is all disabled (in my setup) and that leads me to think nothing is being sent. Back to the system menu. But it was nice learning about the Controls window and if I need to set up something else with it - I should be able to.

1 Like

I guess I am back to the original question of how do I display feedback when a System Command message is used.

I would guess that you're down to a compromise:

  1. Create a script called ~/scripts/myscript
  2. Do the sudoers.d thing described earlier if that requires root access
  3. The first line should be a shebang for bash
  4. Use redirection to send the output(s) to a log file
command >> /var/log/myscript.log 2>&1

This should send both STDOUT and STDERR to the same file. There might be a way of directing the logs to the ~/.octoprint/logs folder so that they appear in the Settings -> Logs listing. And there's nothing to prevent you from redirecting to the existing ~/.octoprint/logs/octoprint.log file itself, to be honest.

Otherwise, you might have to write something like a plugin.

You might be able to take advantage of any existing plugin which does notifications, especially from a command line. So perhaps growl or MQTT might be the way to go.

WOW -thanks.
That is a lot of leads to follow!
I was wondering about the text message thing for another project of mine so these are really great.
The right way to do this would be a plugin. I should probably learn how to do that anyway.
I found a document that has two different levels of plugin instruction. I plan to make use of those soon.

Thanks again,

For example, you might growl (prowl) from that script.

./prowl.pl -apikeyfile=prowl_key.txt -event="Some Topic" -notification="Hello from RasPi"

In this case instead of saying hello, you'd first store the output from earlier into a variable and then throw it to prowl.

That's going to take some looking up. I am not familiar with growl. This is going to take some time.

Take your time. I'm mostly teaching you that there are numerous ways of communicating data between any two endpoints.