Click here to Skip to main content
15,888,046 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
So I have researched this for about 3 days now and everything that I find doesn't work or throws 10+ Errors. I am trying take the output from a batch file (CMD Window that shows generated strings) and insert it into TextBox1 on my VB Form1. So when I push the button, the batch is executed which opens up (on toolbar) a CMD window, shows the strings as they are produced while being inserted into what might be an open file dialog but for now its textbox1.(multiline)
Is there a way to do this and/or is this where create pipeline comes in? I apologize in advance I am a week old beginner. Below is what I have for button1.



VB
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Shell("C:\Test.bat")

    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        Dim myprocess As New Process
        Dim StartInfo As New System.Diagnostics.ProcessStartInfo
        StartInfo.FileName = "cmd" 'starts cmd window
        StartInfo.RedirectStandardInput = True
        StartInfo.RedirectStandardOutput = True
        StartInfo.UseShellExecute = False 'required to redirect
        StartInfo.CreateNoWindow = True '<---- creates no window, obviously
        myprocess.StartInfo = StartInfo
        myprocess.Start()
        Dim SR As System.IO.StreamReader = myprocess.StandardOutput
        Dim SW As System.IO.StreamWriter = myprocess.StandardInput
        SW.WriteLine(TextBox1) 'the command you wish to run.....
        SW.WriteLine("exit") 'exits command prompt window
        txtResults.Text = SR.ReadToEnd 'returns results of the command window
        SW.Close()
        SR.Close()
    End Sub
End Class
Posted

1 solution

If TextBox1 contains the command to execute, why not simply pass it as StartInfo.Arguments?
http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.arguments(v=vs.110).aspx[^]

Have a look at this; there might be something useful in there:
ProcessCommunicator[^]


Also, you don't need to create a new StartInfo.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900