C#调用命令行返回参数方法
来源:互联网 发布:mac放视频卡住了怎么办 编辑:程序博客网 时间:2024/05/18 02:44
public string Execute(string dosCommand, int milliseconds)
{
string output = ""; //输出字符串
if (dosCommand != null && dosCommand != "")
{
Process process = new Process(); //创建进程对象
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "cmd.exe"; //设定需要执行的命令
startInfo.Arguments = "/C " + dosCommand; //设定参数,其中的“/C”表示执行完命令后马上退出
startInfo.UseShellExecute = false; //不使用系统外壳程序启动
startInfo.RedirectStandardInput = false; //不重定向输入
startInfo.RedirectStandardOutput = true; //重定向输出
startInfo.CreateNoWindow = true; //不创建窗口
process.StartInfo = startInfo;
try
{
if (process.Start()) //开始进程
{
if (milliseconds == 0)
process.WaitForExit(); //这里无限等待进程结束
else
process.WaitForExit(milliseconds); //这里等待进程结束,等待时间为指定的毫秒
output = process.StandardOutput.ReadToEnd();//读取进程的输出
}
}
catch
{
}
finally
{
if (process != null)
process.Close();
}
}
return output;
}
{
string output = ""; //输出字符串
if (dosCommand != null && dosCommand != "")
{
Process process = new Process(); //创建进程对象
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "cmd.exe"; //设定需要执行的命令
startInfo.Arguments = "/C " + dosCommand; //设定参数,其中的“/C”表示执行完命令后马上退出
startInfo.UseShellExecute = false; //不使用系统外壳程序启动
startInfo.RedirectStandardInput = false; //不重定向输入
startInfo.RedirectStandardOutput = true; //重定向输出
startInfo.CreateNoWindow = true; //不创建窗口
process.StartInfo = startInfo;
try
{
if (process.Start()) //开始进程
{
if (milliseconds == 0)
process.WaitForExit(); //这里无限等待进程结束
else
process.WaitForExit(milliseconds); //这里等待进程结束,等待时间为指定的毫秒
output = process.StandardOutput.ReadToEnd();//读取进程的输出
}
}
catch
{
}
finally
{
if (process != null)
process.Close();
}
}
return output;
}
0 0
- C#调用命令行返回参数方法
- C# Main方法及命令行参数
- 命令行参数 opencv调用
- C#老生常谈之异步调用的参数及返回值
- C#老生常谈之异步调用的参数及返回值
- C# 调用易语言dll 返回文本参数
- C#老生常谈之异步调用的参数及返回值
- C#调用存储过程带输出参数或返回值
- c#调用带参数或返回值的存储过程
- C#线程调用带参数的方法
- C#线程调用带参数的方法
- C#线程调用带参数的方法 ~
- C#线程调用带参数的方法 ~
- c#多线程调用有参数的方法
- c# 调用带参数的js方法
- C# JS调用后台带参数方法
- C#线程调用带参数的方法
- C#线程调用带参数的方法
- ArrayAdapter(数组适配器)与SimpleAdapter(简单适配器)
- eclipse调试yarn
- 下拉树列表菜单选择器
- ACM比赛中通过freopen读取测试用例
- PAT (Advanced Level) 1082. Read Number in Chinese (25) 数字转汉字大写
- C#调用命令行返回参数方法
- Managing your Applications在同一个CI中设置多个application文件夹
- 控制台打印android信息
- win10卸载OneDrive
- 性能分析工具gprof介绍
- 【未测试】使用mysql-proxy 快速实现mysql 集群 读写分离
- KVO和KVC
- 嵌套Fragment startActivityForResult解决方案
- 各种分布及应用场合(建模对象)