Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute console command and get its output

Tags:

.net

vb.net

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)?

like image 534
Peter Lee Avatar asked Dec 20 '25 08:12

Peter Lee


1 Answers

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()
like image 54
dtb Avatar answered Dec 23 '25 01:12

dtb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!