using
System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
namespace BaseCMD
{
static class MyCMD
{
static string cmdStr, reStr;
static Process p;
static public string RunCMD_HideForm( string cmd) // 后台调用CMD,执行命令,返回结果字符串
{
cmdStr = "" ;
reStr = "" ;
if (cmd == null || cmd.Length == 0 )
{
cmdStr = "" ;
}
else
{
cmdStr = cmd;
}
p = new Process();
p.StartInfo.FileName = " cmd.exe " ;
p.StartInfo.UseShellExecute = false ;
p.StartInfo.RedirectStandardInput = true ; // 可能接受来自调用程序的输入信息
p.StartInfo.RedirectStandardOutput = true ; // 由调用程序获取输出信息
p.StartInfo.CreateNoWindow = true ; // 不显示程序窗口
p.Start(); // 启动程序
p.StandardInput.WriteLine(cmdStr);
reStr = p.StandardOutput.ReadToEnd();
return reStr;
}
}
}
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
namespace BaseCMD
{
static class MyCMD
{
static string cmdStr, reStr;
static Process p;
static public string RunCMD_HideForm( string cmd) // 后台调用CMD,执行命令,返回结果字符串
{
cmdStr = "" ;
reStr = "" ;
if (cmd == null || cmd.Length == 0 )
{
cmdStr = "" ;
}
else
{
cmdStr = cmd;
}
p = new Process();
p.StartInfo.FileName = " cmd.exe " ;
p.StartInfo.UseShellExecute = false ;
p.StartInfo.RedirectStandardInput = true ; // 可能接受来自调用程序的输入信息
p.StartInfo.RedirectStandardOutput = true ; // 由调用程序获取输出信息
p.StartInfo.CreateNoWindow = true ; // 不显示程序窗口
p.Start(); // 启动程序
p.StandardInput.WriteLine(cmdStr);
reStr = p.StandardOutput.ReadToEnd();
return reStr;
}
}
}