alright, I can successfully use Process.Start to open up the command prompt, but how can I pass it a string to open with? Do I have to call a batch file to do this?
I don't think you can cause it to enter text (My history of making batch files never been able to do this.) You can only create an individual batch file to do what you need that batch file to do.
Sorry dont use my original code it will be harder to debug.
Public Sub ProcessFile()
Try
Dim process As System.Diagnostics.Process = New System.Diagnostics.Process
‘process.StartInfo.FileName = "C:\Windows\system32\cmd.exe"
process.StartInfo.FileName = "C:\Windows\system32\command.com"
process.StartInfo.Arguments = "/C COMAND"
process.StartInfo.UseShellExecute = True
process.Start()
process.WaitForExit()
Catch ex As Exception
MsgBox(ex.Message)
Me.Dispose()
End Try
End Sub
This comes form Microsoft modify this to your needs, it will also catch any errors.
'requires Imports System.IO
Public Function RunTerminalCommand(ByVal TerminalCommand As String) As String
Dim usecommand As String = Environment.GetEnvironmentVariable("COMSPEC")
Return ShellCapture(usecommand, "/C " + TerminalCommand)
End Function
Public Function ShellCapture(ByVal ProgramName As String,ByVal CommandRun As String) As String
Return ShellCapture(ProgramName,CommandRun,True)
End Function
Public Function ShellCapture(ByVal ProgramName As String, ByVal CommandRun As String,DoRedirect As Boolean) As String
Dim psi As New ProcessStartInfo(ProgramName, CommandRun)
Dim result As String = ""
psi.RedirectStandardOutput = DoRedirect
psi.RedirectStandardError = DoRedirect
'if you want to hide the program you are executing, you can use the ProcessWindowStyle.Hidden.
psi.WindowStyle = ProcessWindowStyle.Normal
psi.UseShellExecute = False
Dim exectask As Process = Process.Start(psi)
if Not DoRedirect Then return ""
Using outputreader = exectask.StandardOutput
result = outputreader.ReadToEnd()
End Using
Using errorreader = exectask.StandardError
result += errorreader.ReadToEnd()
End Using
Return result + Environment.NewLine
End Function
Example usage:
Sub Main()
Dim dirresult As String = RunTerminalCommand("dir D: /w")
'dirresult has text resulting from execution of the command.
Console.WriteLine("dir:")
Console.WriteLine(dirresult)
End Sub
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
I don't think you can cause it to enter text (My history of making batch files never been able to do this.) You can only create an individual batch file to do what you need that batch file to do.
Or this, will have to remember this.
awesome, thank you!
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Example usage:
LOL at the broken syntax colouring.