Python Forum

Full Version: Filtering an interactive CLI command via pipe(s)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
i have one or more CLI commands to run.  they could be run in a Python script by using subprocess.call though this is not the ultimate method.  what i would like to do is make a Python script frontend that filters the input and filters the output.  by filter i mean some kind of processing i decide on such as appending changing filename extensions on inputs and adding timestamps on outputs.  so there certainly needs to be a pipe or pipes between the filter script and the stdin and stdout of the interactive program to be run.

i am looking for examples of this kind of code or descriptions of exactly what to do (code).
Something like:
ls | myscript.py | cat
That could be as easy as just reading stdin and print()ing out, and letting the os handle piping?
(Nov-15-2016, 08:45 PM)nilamo Wrote: [ -> ]Something like:
ls | myscript.py | cat
That could be as easy as just reading stdin and print()ing out, and letting the os handle piping?

i have done things like that in shell script.  i want to do it all in python.  there may be cases where i will feed output back to input.  gotta be careful to avoid totally (b)locking.  that's why i want to use python.