Why isn't reading StandardOut working?

I'm currently trying to write a little post-review wrapper to automatically post, but this feature doesn't work when it comes to Dim results As String = sOut.ReadToEnd()

, and I can't tell you why.

Edit: it doesn't throw an error, apparently just goes to ReadToEnd () to never return

Am I just missing something obvious?

Function postReview() As String
            Dim psi As ProcessStartInfo = New System.Diagnostics.ProcessStartInfo("cmd.exe")
            psi.UseShellExecute = False
            psi.RedirectStandardOutput = True
            psi.RedirectStandardInput = True
            psi.RedirectStandardError = True
            Dim proc As Process = System.Diagnostics.Process.Start(psi)
            Dim strm As StreamReader = proc.StandardError
            Dim sOut As StreamReader = proc.StandardOutput
            Dim sIn As StreamWriter = proc.StandardInput
            MsgBox()
            sIn.WriteLine("cd " & IO.Directory.GetCurrentDirectory)

            sIn.WriteLine(Me.ToString)
            sIn.WriteLine("post-review.py -d --username=User --password=Pass")
            Dim results As String = sOut.ReadToEnd()

            sIn.WriteLine("exit")
            sIn.Close()
            sOut.Close()


            Return results

        End Function

      

Additional information: The actual team is working as I can see its publication on the Supervisory Board. But it seems like it is stuck in a loop waiting for the Stream to complete.

I've tried reading and reading with no luck

0


a source to share


3 answers


Exchange:

Dim results As String = sOut.ReadToEnd()
sIn.WriteLine("exit")
sIn.Close()
sOut.Close()

      

from



sIn.WriteLine("exit")
Dim results As String = sOut.ReadToEnd()
psi.WaitForExit()

      

I am assuming there is no "end" of the output stream since you have not yet exited. However, the exit must be available after the exit.
And you don't need to close the threads, but you can wait until the process completes (last line of code)

+1


a source


I think it might be this line causing you problems:

psi.UseShellExecute = True

      



From the documentation :

To use StandardOutput you must set ProcessStartInfo.UseShellExecute to false and you must set ProcessStartInfo.RedirectStandardOutput to true

+1


a source


Try Read or ReadLine.

0


a source







All Articles