Python Forum
Filtering an interactive CLI command via pipe(s)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Filtering an interactive CLI command via pipe(s)
#1
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).
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
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?
Reply
#3
(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.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Media Pipe Python Interfacing with MATLAB cmcreecc 1 152 May-30-2024, 07:23 AM
Last Post: TrentErnser
  Convert Excel file into csv with Pipe symbol.. mg24 4 1,448 Oct-18-2022, 02:59 PM
Last Post: Larz60+
  BrokenPipeError: [Errno 32] Broken pipe throwaway34 6 9,849 May-06-2021, 05:39 AM
Last Post: throwaway34
  interactive map and function hurc60248 1 1,828 Jan-08-2021, 09:22 PM
Last Post: Larz60+
  2 or more processes on the write end of the same pipe Skaperen 4 3,995 Sep-27-2020, 06:41 PM
Last Post: Skaperen
  multiprocessing Pipe.poll very slow seandepagnier 0 2,415 Mar-09-2020, 03:10 AM
Last Post: seandepagnier
  for / else not working in interactive mode Skaperen 4 2,658 Jul-17-2019, 06:16 PM
Last Post: Skaperen
  faster socket with multiprocessing.Pipe sixteenornumber 2 6,697 Dec-10-2016, 06:52 PM
Last Post: sixteenornumber

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020