Execute Shell Script with Argument 😧

What I have missed? Or maybe a bug...

Execute Shell Script with Argument :anguished:.kmmacros (2.9 KB)

-alain

I think your python might be the problem. This works:

#!/usr/bin/python
import sys
for line in sys.stdin:
    print line

Shell Script with Variable.kmmacros (2.4 KB)

@iNik Thanks you helped me clarify argument and STDIN input. On the other hand my Python 3 script works perfectly but can only display the only argument it now receives with this KM action...
Here is a new version which integrates STDIN:

#!/opt/local/bin/python3
# -*- coding: utf-8 -*-

# km-8.2-execute-shell-script-argument-and-stdin.py

from sys import argv,exit,stdin
print('stdin:',"'"+list(stdin)[0]+"'")
print('temporary scipt file:',"'"+argv[0]+"'");print();exit()

@peternlewis Feature request: It would be desirable that this KM action integrates the passage of arguments as it already allows with STDIN: it is one of the important features of shell scripts.

Arguments ca be passed via variables. I doubt I would add support for passing arguments to the shell script per se.

In fact, my request is made for the case where the shell script (whatever the language) is specified by a file: it can thus be executed without modification whatever the context of shell execution directly / KM (shell indirectly) :wink:

You can just run a "text script" that invokes the file along with the appropriate KM variable(s).

image

1 Like

Of course, due to richness of KM and shell scripts we can survived by one way or an other :wink:

You probably want to add double quoting around the argument:

~/Downloads/test.py "$KMVAR_InstanceArgument"

to ensure proper argument handling.

Fair enough, as @iNik says, you can just use a path instead. It's not an unreasonable request, but it seems a lot of work and a lot of UI complexity to add a facility that can already be accomplished relatively easily.

1 Like