Method run.console(+ 2 overloads)
Overload
Runs a console program in hidden mode, waits until its process ends, and prints its output text. Writes text lines to the output in real time.
public static int console(string exe, string args = null, string curDir = null, Encoding encoding = null)
Parameters
exe (string)
Path or name of an
|
args (string)
|
curDir (string)
Initial current directory of the new process.
|
encoding (Encoding)
Console's text encoding.
If |
Returns
int
The process exit code. Usually a non-0 value means error. |
Exceptions
AuException
Failed, for example file not found. |
Remarks
The console window is hidden. The text that would be displayed in it is redirected to this function.
Console programs have two output text streams - standard output and standard error. This function gets both. Alternatively use System.Diagnostics.Process.Start; it gets the output and error streams separately, and some lines may be received in incorrect order in time.
Examples
string v = "example";
run.console(@"C:\Test\console.exe", $@"/an ""{v}"" /etc");
Overload(next)
Runs a console program in hidden mode, waits until its process ends, and gets its output text.
public static int console(out string output, string exe, string args = null, string curDir = null, Encoding encoding = null)
Parameters
output (string)
A variable that receives the output text. |
exe (string)
Path or name of an
|
args (string)
|
curDir (string)
Initial current directory of the new process.
|
encoding (Encoding)
Console's text encoding.
If |
Returns
int
The process exit code. Usually a non-0 value means error. |
Exceptions
AuException
Failed, for example file not found. |
Remarks
The console window is hidden. The text that would be displayed in it is redirected to this function.
Console programs have two output text streams - standard output and standard error. This function gets both. Alternatively use System.Diagnostics.Process.Start; it gets the output and error streams separately, and some lines may be received in incorrect order in time.
Examples
run.console(out var text, @"C:\Test\console.exe", encoding: Console.OutputEncoding);
print.it(text);
Overload(top)
Runs a console program in hidden mode, waits until its process ends, and gets its output text. Uses a callback function that receives text lines in real time.
public static int console(Action<string> output, string exe, string args = null, string curDir = null, Encoding encoding = null, bool rawText = false)
Parameters
output (Action<string>)
Callback function that receives the output text.
Unless rawText
|
exe (string)
Path or name of an
|
args (string)
|
curDir (string)
Initial current directory of the new process.
|
encoding (Encoding)
Console's text encoding.
If |
rawText (bool)
Call the callback function whenever text is retrieved (don't wait for full line). Pass raw text, in chunks of any size. |
Returns
int
The process exit code. Usually a non-0 value means error. |
Exceptions
AuException
Failed, for example file not found. |
Remarks
The console window is hidden. The text that would be displayed in it is redirected to this function.
Console programs have two output text streams - standard output and standard error. This function gets both. Alternatively use System.Diagnostics.Process.Start; it gets the output and error streams separately, and some lines may be received in incorrect order in time.
Examples
run.console(s => print.it(s), @"C:\Test\console.exe");
run.console(s => { print.it($"<><_>{s}</_><nonl>"); }, @"C:\Test\console.exe", rawText: true);