cmd icon indicating copy to clipboard operation
cmd copied to clipboard

How to hide cmd windows?

Open nabeghe opened this issue 7 years ago • 2 comments

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

nabeghe avatar Apr 30 '18 13:04 nabeghe

// 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.");

catcake avatar Apr 03 '19 06:04 catcake

you can modify "ProcessRunner.cs" Snipaste_2021-06-28_08-45-57

weizai avatar Jun 28 '21 00:06 weizai