subprocessライブラリでパイプ処理をする

前回の続き。 シェルの醍醐味(?)といえばパイプ処理。 実際のところ output=`dmesg | grep hda`に相当するコマンドが、以下の様に。 p1 = Popen(["dmesg"], stdout=PIPE) p2 = Popen(["grep", "hda"], stdin=p1.stdout, stdout=PIPE) #入力はp1のstdout p1.stdout.close() # 他のプロセスがあったとき、p1がSIGPIPEを掴…