cmd
cmd copied to clipboard
How to hide cmd windows?
When I run command, the main cmd opened and close fastly. How to hide it?
dynamic cmd = new Cmd();
var output = cmd.ipconfig();
MessageBox.Show(output);
// late reply (oops). The window briefly opening is a side effect of the way the cmd is written; it is designed to execute commands using cmd.exe (or another shell), not directly.
Substantial changes would have to be made to bring this functionality to cmd & I believe it's out of the scope too.
This strays from the simplicity this library offers, however the following snippet has the functionality desired.
// Launches ipconfig, captures the output, & reports its line count.
const string processName = "ipconfig.exe";
var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = processName,
RedirectStandardOutput = true,
RedirectStandardError = true
}
};
process.Start();
const int timeOut = 5000;
if (!process.WaitForExit(timeOut))
{
Console.WriteLine($"{processName} did not finish within the allotted time: {timeOut}ms.");
return;
}
string output = process.StandardOutput.ReadToEnd();
int outputLines = output.Split(Environment.NewLine).Length;
Console.WriteLine($"{processName} had {outputLines} lines of output.");
you can modify "ProcessRunner.cs"
