I recently building codes for cmd commands by vb.net. It cannot work by just popping up the same form. I hope that someone can fix it.
Imports System.IO
Public Class Form1
Private Sub Execute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Execute.Click
Result.Text = RunCmd(Command.Text)
End Sub
Private Function RunCmd(ByVal cmd As String) As String
Dim p As Process = New Process
With p.StartInfo
.FileName = "cmd.exe"
.Arguments = "/c " + cmd
.UseShellExecute = False
.RedirectStandardInput = True
.RedirectStandardOutput = True
.RedirectStandardError = True
.CreateNoWindow = True
End With
p.Start()
'p.StandardInput.WriteLine(command);
'p.StandardInput.WriteLine("exit");
Dim reader As StreamReader = p.StandardOutput
Dim output As String = reader.ReadToEnd()
Return output
End Function
End Class
I expect that I can run the command in the textbox. But it can't.