title: How to I read cmd output in VB.NET from cmd shell?
body: <p>I am using gnokii to send out SMSes.</p>
  
  <p>My VB Codes:</p>
  
  <pre><code>Dim xCmd As String
  xCmd = "cmd.exe /c echo msgcontent "| c:\gnokii\gnokii.exe --sendsms 12345678"
  Shell(xCmd)
  </code></pre>
  
  <p>Points to note:</p>
  
  <ol>
  <li><p>I did try to redirect the output to a .txt file but the .txt file appears to be empty. Besides, the program may have to send out multiple SMSes every second, so creating a .txt is not feasible.</p></li>
  <li><p>Process.Start() is not feasible because I have to check if gnokii.exe is running.</p></li>
  <li><p>I need the output to check if the SMS is sent successfully.</p></li>
  <li><p>I tried using (codes below), but it didn't work either; no output was shown.</p>
  
  <p>Function exe(ByVal fileName, ByVal args)</p>
  
  <pre><code>Dim p As Process = New Process
  Dim output As String
  
  With p
      .StartInfo.CreateNoWindow = True
      .StartInfo.UseShellExecute = False
      .StartInfo.RedirectStandardOutput = True
      .StartInfo.FileName = fileName
      .StartInfo.Arguments = args
      .Start()
      output = .StandardOutput.ReadToEnd
  End With
  
  Return output
  </code></pre>
  
  <p>End Function</p></li>
  </ol>