Hi guys/gals,
I have a small problem that when I open cmd.exe and send commands to it I see the command prompt open and the command runs but I don't see any text in the window. when the command finishes I get the result in a rich text box. How can I see the code run in the command window? some commands can take a long time so I want to know that something is going on.
Code:Dim CmdString As String = "" If RadioBtnApply.Checked = True Then CmdString = "dism /apply-image /imagefile:" & TxtImageFile.Text & " /index:1 /applydir:C:\" ElseIf RadioBtnCapture.Checked = True Then CmdString = "dism /Capture-Image /ImageFile:" & TxtImageFile.Text & " /CaptureDir:C:\ /name:""" & OS & """ /compress:fast" ElseIf RadioBtnDiskpart.Checked = True Then CmdString = "diskpart /s diskpartcmds.txt" End If ' MsgBox(CmdString) p.StartInfo.FileName = "cmd.exe" ' p.StartInfo.Arguments = " /K " ' /C runs string then exits, /K runs string then stays ' p.StartInfo.CreateNoWindow = True 'True to hide the console window p.StartInfo.UseShellExecute = False 'must have set p.StartInfo.RedirectStandardOutput = True 'must have set p.StartInfo.RedirectStandardInput = True p.EnableRaisingEvents = True 'used to receive the Process`s Exited event p.Start() 'p.StandardInput.WriteLine(CmdString) Dim SR As System.IO.StreamReader = p.StandardOutput Dim SW As System.IO.StreamWriter = p.StandardInput SW.WriteLine("Applying Image") SW.WriteLine(CmdString) 'the command you wish to run..... 'SW.WriteLine("exit") 'exits command prompt window RichTextBox1.Text = SR.ReadToEnd 'returns results of the command window SW.Close() SR.Close()


Reply With Quote