0

I want to pass output from one python script into another one as in

python -c $'print("world")' | python -c $'import sys \nprint("hello " + sys.stdin.readline())'

which works quite well.

Now the first one is to be replaced to have

mbed detect | python -c $'import sys \nprint("hello " + sys.stdin.readline())'

This yields an error

hello

Traceback (most recent call last):
  File "C:\Users\ere\...\mbed-os\tools\detect_targets.py", line 90, in main
    print(mcu_toolchain_matrix(platform_filter=mut['mcu']))
OSError: [Errno 22] Invalid argument

On the other hand, mbed detect invoked alone yields reasonable output. The mbed tool is installed via pip install mbed-cli and as i can see installation creates a file mbed.exe. This means it is an application written in python and compiled into an exe. Maybe that latter is the step where piping gets broken??? I can see in the stacktrace that problem occurs in the source with print("")

            print("")
            print("[mbed] Detected %s, port %s, mounted %s, interface "
                  "version %s:" %
                  (mut['mcu'], mut['port'], mut['disk'], interface_version))
            print("[mbed] Supported toolchains for %s" % mut['mcu'])
            #print(mcu_toolchain_matrix(platform_filter=mut['mcu']))
            count += 1

Note that i commented out another print. If i dont, that problem occurs at that place. Very strange..

Help very much appreciated.

user2609605
  • 177
  • 12
  • _I want to pass output from one python script into another one as in_ Is there a particular reason you're doing things that way? – AMC Mar 17 '20 at 16:59
  • Well yes, the first one is mbed, this is a common tool. ```mbed detect``` yields a description of hardware attached. This string i want to parse, e.g. to find out the port at which it is attached. – user2609605 Mar 18 '20 at 09:19
  • Have you considered just running it inside the script? [Some examples here.](https://stackoverflow.com/questions/89228/calling-an-external-command-from-python) – char Mar 18 '20 at 09:24

0 Answers0