Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to hide cmd windows? #9

Open
nabeghe opened this issue Apr 30, 2018 · 2 comments
Open

How to hide cmd windows? #9

nabeghe opened this issue Apr 30, 2018 · 2 comments

Comments

@nabeghe
Copy link

nabeghe commented Apr 30, 2018

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);
@catcake
Copy link

catcake commented Apr 3, 2019

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

@weizai
Copy link

weizai commented Jun 28, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants