私はリストからコマンドパラメータを取得し、最後のstdoutを新しいstdinにパイプするループでシェルパイプラインを作成する関数を作成しようとしています。 コマンドリストの中で、私はPopenオブジェクトの通信メソッドを呼び出して出力を取得します。Python popen pipe in loop
出力は常に空です。私は間違って何をしていますか?
次の例を参照してください。私は、追加のUNIX機能を備えたWindows環境によ
lstCmd = ["tasklist", "grep %SESSIONNAME%", "grep %s" % (strAutName)]
lstPopen = [subprocess.Popen(lstCmd[0].split(), stdout=subprocess.PIPE)]
for i in range(len(lstCmd) - 1):
lstPopen.append(subprocess.Popen(lstCmd[i + 1].split(), stdin=lstPopen[i].stdout, stdout=subprocess.PIPE))
lstPopen[i].stdout.close()
strProcessInfo = lstPopen[-1].communicate()[0]
を。私のWindowsコマンドライン上のコマンドの機能に従い、strProcessInfoに書き込まする必要があります。
C:\>tasklist | grep %SESSIONNAME% | grep tasklist
tasklist.exe 18112 Console 1 5.948 K
** Console **を** os.environ ["SESSIONNAME"]で置き換えただけですが**正常でした。ありがとうございました! –