Requirement - I want to execute a command that uses ls, grep, head etc using pipes (|). I am searching for some pattern and extracting some info which is part of the query my http server supports.
The final output should not be too big so m assuming stdout should be good to use (I read about deadlock issues somewhere) Currently, I use popen from subprocess module but I have my doubts over it.
I am new to Python and links to videos/articles are also appreciated. Any other way than popen is also fine.
You could use os.listdir
or os.walk
instead of ls
, and the re
module instead of grep
.
Wrap everything up in a function, and use eg the map
method from a multiprocessing.Pool
object to run several of those in parallel. This is a pattern that works very well.
In Python3 you can also use Executors
from concurrent.futures
in a similar way.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.