Fourteen Years of Service
Posts: 2,622
Threads: 213
RE: how to execute console commands from form application? 06-20-2011, 08:25 PM
#4
It's an example.
I'm not sure how to store the response.
![[Image: rytwG00.png]](http://i.imgur.com/rytwG00.png)
Redcat Revolution!
•
Fourteen Years of Service
Posts: 107
Threads: 4
RE: how to execute console commands from form application? 06-20-2011, 08:45 PM
#6
Private Sub readthatthing()
Dim output As String
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
myprocess.StartInfo = StartInfo
myprocess.Start()
Dim SR As System.IO.StreamReader = myprocess.StandardOutput
Dim SW As System.IO.StreamWriter = myprocess.StandardInput
SW.WriteLine("ping 192.168.0.1") 'the command you wish to run.....
SW.WriteLine("exit") 'exits command prompt window
output = SR.ReadToEnd 'returns results of the command window
SW.Close()
SR.Close()
MsgBox(output)
End Sub
•
Fourteen Years of Service
Posts: 107
Threads: 4
RE: how to execute console commands from form application? 06-22-2011, 11:05 PM
#8
yeah, ProcessStartInfo gives you just that little extra control over a process.. just follow the syntax rules and you'll be able to pass any verb or argument to the process..
examples:
Verb: open process Notepad and make it print
argument: open process Notepad and have text displayed into it...
Just remember you'll have to define the file name, which could be any program or document as long as there exist an association..
The UseShellExecute defines if the process should or shouldn't be handled by the os shell.
In normal cases, Input is most likely the keyboard, while Output would be the monitor...by defining REDIRECTION however you'll have control over in & output
•