Windows で Python 3.0 を使用しており、コマンドライン アプリケーションのテストを自動化しようとしています。ユーザーは Application Under Test にコマンドを入力でき、出力が 2 つの XML パケットとして返されます。1 つはパケットで、もう 1 つはパケットです。これらのパケットを分析することで、結果を検証できます。私は以下のようにコードをahev
p = subprocess.Popen(SomeCmdAppl, stdout=subprocess.PIPE,
shell = True, stdin=subprocess.PIPE, stderr=subprocess.STDOUT)
p.stdin.write((command + '\r\n').encode())
time.sleep(2.5)
testresult = p.stdout.readline()
testresult = testresult.decode()
print(testresult)
出力を戻すことができません。readline() を使用して出力を読み取ろうとした場所でスタックします。read() を試しましたが、それもスタックします
コマンドライン アプリケーションを手動で実行してコマンドを入力すると、出力が以下のように 2 つの xml パケットとして正しく返されます。
Sent: <PivotNetMessage>
<MessageId>16f8addf-d366-4031-b3d3-5593efb9f7dd</MessageId>
<ConversationId>373323be-31dd-4858-a7f9-37d97e36eb36</ConversationId>
<SageId>4e1e7c04-4cea-49b2-8af1-64d0f348e621</SagaId>
<SourcePath>C:\Python30\PyNTEST</SourcePath>
<Command>echo</Command>
<Content>Hello</Content>
<Time>7/4/2009 11:16:41 PM</Time>
<ErrorCode>0</ErrorCode>
<ErrorInfo></ErrorInfo>
</PivotNetMessagSent>
Recv: <PivotNetMessage>
<MessageId>16f8addf-d366-4031-b3d3-5593efb9f7dd</MessageId>
<ConversationId>373323be-31dd-4858-a7f9-37d97e36eb36</ConversationId>
<SageId>4e1e7c04-4cea-49b2-8af1-64d0f348e621</SagaId>
<SourcePath>C:\PivotNet\Endpoints\Pipeline\Pipeline_2.0.0.202</SourcePath>
<Command>echo</Command>
<Content>Hello</Content>
<Time>7/4/2009 11:16:41 PM</Time>
<ErrorCode>0</ErrorCode>
<ErrorInfo></ErrorInfo>
</PivotNetMessage>
しかし、以下のように communicate() を使用すると、Sent パケットを取得し、Recv: パケットを取得しません。recv パケットが見つからないのはなぜですか? communicate(0 は stdout.rt?
p = subprocess.Popen(SomeCmdAppl, stdout=subprocess.PIPE,
shell = True, stdin=subprocess.PIPE, stderr=subprocess.STDOUT)
p.stdin.write((command + '\r\n').encode())
time.sleep(2.5)
result = p.communicate()[0]
print(result)
動作するはずのサンプル コードを手伝ってくれる人はいますか? 別のスレッドで読み書きする必要があるかどうかはわかりません。私を助けてください。読み取り/書き込みを繰り返す必要があります。私が使用できるPythonの高度なレベルのモジュールはありますか。Pexpect モジュールが Windows で動作しないと思います