public class BlackWindow
{
private static BlackWindow _instance;
public static BlackWindow Instance
{
get
{
if (_instance == null)
_instance = new BlackWindow();
return _instance;
}
}
public System.Diagnostics.Process pro { set; get; }
BlackWindow()
{
//下面StartInfo的UseShellExecute和RedirectStandardInput/Output选项为互斥选项
//若设置UseShellExecute=true代表使用dos黑窗口,但RedirectStandardInput/Output必须为false,表示输入输出也只能通过dos窗口手工录入,不能通过StandardInput.WriteLine输入
//若要显示Dos窗口,但又想通过程序输入命令,只能用StartInfo.Arguments = cmdLine;但该参数只能输入一行
//StartInfo.Arguments命令前一定要加/k表示打开新窗口,否则运行结果无法显示
pro = new System.Diagnostics.Process();
pro.StartInfo.FileName = "cmd.exe";
//pro.StartInfo.UseShellExecute = false; //true代表使用dos窗口,默认true
//pro.StartInfo.RedirectStandardInput = true;
// pro.StartInfo.RedirectStandardOutput = true;
//pro.StartInfo.CreateNoWindow = true;
}
public void Start(string cmdLine)
{
pro.StartInfo.Arguments = cmdLine;
pro.StartInfo.WorkingDirectory = "";//工作目录
pro.Start();
//pro.StandardInput.WriteLine(cmdLine);
pro.WaitForExit();
pro.Close();
}
}