Execute console command and get its output

2020-07-22 20:19发布

问题:

I'm wondering, in Visual Basic 2008, how to execute an external console (commandline) command and get its output without help of an intermediate file (to speed up)?

回答1:

Have a look at ProcessStartInfo.RedirectStandardOutput and Process.StandardOutput.

Example:

compiler.StartInfo.FileName = "csc.exe"
compiler.StartInfo.Arguments = "/r:System.dll /out:sample.exe stdstr.cs"
compiler.StartInfo.UseShellExecute = False
compiler.StartInfo.RedirectStandardOutput = True
compiler.Start()

Console.WriteLine(compiler.StandardOutput.ReadToEnd())

compiler.WaitForExit()


标签: .net vb.net