1

複数のコマンド ライン プロセスを実行し、それらをループで開始します。それは機能し、それらすべてを非同期で開始します。

Public Sub DoWork
Dim i As Integer = 0
        While (Args_reader.Peek() > -1)
            i = i + 1
            MyArg = Args_reader.ReadLine
            Dim MyArg As String
            Dim MyProcess(i) As Process
            MyProcess(i) = New Process
            With MyProcess(i).StartInfo
                .FileName = MyFile
                .Arguments = MyArg
                .UseShellExecute = False
                .CreateNoWindow = True
                .RedirectStandardInput = True
                .RedirectStandardOutput = True
                .RedirectStandardError = True
                .WindowStyle = ProcessWindowStyle.Hidden
            End With
            MyProcess(i).Start()
        End While
        Args_reader.Close()
        i = 0
End Sub

それらすべての stdOutput を読み取ってステータスを確認するにはどうすればよいですか? プログラムの実行を続行するには、彼らが終了するまで待つ必要があります。

4

1 に答える 1

0

asyncイベントをevery processループ内に割り当てることをお勧めします。これにより、そのプロセスに出力があるときにイベントが発生します。標準出力またはエラー出力:

 Dim Proceso As New Process

 'Add the event handlers:

 AddHandler Proceso.OutputDataReceived, AddressOf CallbackProcesoAsync
 AddHandler Proceso.ErrorDataReceived, AddressOf ErrorDataReceivedAsync

 Dim startInfo As New ProcessStartInfo
 startInfo.FileName = execFile
 startInfo.RedirectStandardOutput = True
 startInfo.RedirectStandardError = True
 startInfo.CreateNoWindow = False
 Proceso.StartInfo = startInfo
 Proceso.Start()

非同期イベントは次のようになります。

 Private Sub CallbackProcesoAsync(sender As Object, args As System.Diagnostics.DataReceivedEventArgs)

    If Not args.Data Is Nothing AndAlso Not String.IsNullOrEmpty(args.Data) Then

       'args.Data have the output

    End If

End Sub

Private Sub ErrorDataReceivedAsync(sender As Object, args As System.Diagnostics.DataReceivedEventArgs)

   If Not args.Data Is Nothing AndAlso Not String.IsNullOrEmpty(args.Data) Then

       'args.Data have the output

   End If


End Sub
于 2013-10-22T09:41:23.207 に答える