Login Register






how to execute console commands from form application? filter_list
Author
Message
how to execute console commands from form application? #1
hey guyz Smile
i need to know how to execute console commands from a windows form application in VB.NET . i tried shell( ... ) but i seems to be only for opening files
and console.writeline() and console.readline() isnt working
so if there is something to import or there is a another way to do it .. i will be happy if you help Biggrin

Reply

RE: how to execute console commands from form application? #2
Code:
Dim yourCommand As String = "md E:\new" Shell("cmd /c " & yourCommand)

This?
[Image: rytwG00.png]
Redcat Revolution!

Reply

RE: how to execute console commands from form application? #3
yeah... thanks Biggrin but why to make a new directory ? (e:\new)
and how to store the response in a variable ?

Reply

RE: how to execute console commands from form application? #4
It's an example.
I'm not sure how to store the response.
[Image: rytwG00.png]
Redcat Revolution!

Reply

RE: how to execute console commands from form application? #5
mm okay... thx Coder-san

Reply

RE: how to execute console commands from form application? #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

Reply

RE: how to execute console commands from form application? #7
Thanks for that blowdoof, ProcessStartInfo looks very interesting. Smile
[Image: rytwG00.png]
Redcat Revolution!

Reply

RE: how to execute console commands from form application? #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

Reply