tags:

views:

70

answers:

3

I am currently trying to write a little wrapper around post-review to automatically post however this function fails when it comes to Dim results As String = sOut.ReadToEnd() and I can;t suss out why,

Edit: It doesn't produce an error it just seems to go into ReadToEnd() never to 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

Further Info: The actual command is working as I can see it posting to Review Board. But it just seems to get stuck in a loop while waiting on the Stream to complete.

I have tried with Read and Readline with no luck

+1  A: 

I think it might be this line causing you trouble:

psi.UseShellExecute = True

From the documentation:

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

Fredrik Mörk
A: 

Try Read or ReadLine instead.

leppie
+1  A: 

Exchange:

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

with

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

Im guessing there's no "end" of the output stream yet since you haven't exited yet. However the output should still be available after you exit.
And you don't need to close the streams but you might wanna wait til the process has exited (last line of code)

Rune FS