Skip to content

Commit

Permalink
gcode_shell_command: make RUN_SHELL_COMMAND accept optional parameters
Browse files Browse the repository at this point in the history
Thanks @lixxbox for that code
  • Loading branch information
dw-0 authored Oct 17, 2021
1 parent 9b6925e commit f231fa9
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion resources/gcode_shell_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ def _process_output(self, eventime):

cmd_RUN_SHELL_COMMAND_help = "Run a linux shell command"
def cmd_RUN_SHELL_COMMAND(self, params):
gcode_params = params.get('PARAMS','')
gcode_params = shlex.split(gcode_params)
reactor = self.printer.get_reactor()
try:
proc = subprocess.Popen(
self.command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
self.command + gcode_params, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
except Exception:
logging.exception(
"shell_command: Command {%s} failed" % (self.name))
Expand Down

5 comments on commit f231fa9

@jktightwad
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the proper format for passing multiple parameters, for example:
{temp}
{speed}
{flow}

@re3Dev
Copy link

@re3Dev re3Dev commented on f231fa9 Jun 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the proper format for passing multiple parameters, for example: {temp} {speed} {flow}

I am also interested in the correct syntax for this.

@ArsicN
Copy link

@ArsicN ArsicN commented on f231fa9 Mar 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand it's an old commit, but I couldn't seem to find any reference or example on how to pass multiple parameters to a command. So I tested it myself and found a solution. Leaving it here just in case anyone else wants the same and runs into this:
PARAM="{argN1} {argN2} {argN}" if using klippper variables. In my case it was something like: RUN_SHELL_COMMAND cmd=graph_raw_values PARAMS="-a {accel} -c {cruiseratio} -x {axis}" for a custom script I was using. Cheers

@arwiendd
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I am developing a kiosk interface and I developed a macro command in Mainsail. This command allows the WiFi configuration of the Raspberry Pi. I am using the shell-command plugin here. I managed to pass the SSID information to the command, but. I cannot pass the password information, which is the 2nd params. Does anyone have an idea?

My Macro Command:
[gcode_macro WIFI]
gcode:
{% set ssid = params.SSID %}
{% set password = params.Password %}
RUN_SHELL_COMMAND CMD=wifi_connection PARAMS={ssid}{password}

My .sh File:
nmcli device wifi list
SSID="$1"
PASSWORD="$2"
sudo nmcli device wifi connect "$SSID" password "$PASSWORD"

@ArsicN
Copy link

@ArsicN ArsicN commented on f231fa9 Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, so I checked the macro i was using and I have this:

[gcode_shell_command graph_raw_values]
command: bash /home/pi/process-last-accel-raw-values.sh
timeout: 60.
verbose: True

as the shell commands that calls the script. I assume you already defined that gcode_shell_command macro as 'wifi_connection'? If so, the only thing that seems to be missing are the double quotes in the PARAMS= section. Try PARAMS="{ssid} {password}". Add blank space between {ssid} and {password} as I see your script is parsing it as two arguments.
Haven't really played with this in a while, so I'm not exactly sure it will work, but hope it helps. Cheers

Please sign in to comment.