C#创建进程

来源:百度知道 编辑:UC知道 时间:2024/06/18 04:22:10
public string bianyi(string filepath)
{
Process p = new Process();
p.StartInfo.FileName = filepath;
p.StartInfo.UseShellExecute = false;
//重定向标准输入
//p.StartInfo.RedirectStandardInput = false;
//重定向标准输出
p.StartInfo.RedirectStandardOutput = true;
//重定向错误输出
p.StartInfo.RedirectStandardError = false;
//设置不显示窗口
p.StartInfo.CreateNoWindow = true;
string strRst = "";
try
{
//启动进程
p.Start();
//停止3秒钟
Thread.Sleep(1000);
//如果进程结束
if (p.HasExited)
{
//可以带参数
//p.StandardInput.WriteLine("");
//从输出流获取执行结果
strRst = p.StandardOutput.ReadToEnd();

string strtxtPath = "C:\\freezip\\free.txt";
string strzipPath = "C:\\freezip\\free.rar";
System.Diagnostics.Process process1 = new System.Diagnostics.Process();
process1.StartInfo.FileName = "WinRAR.exe";
process1.StartInfo.CreateNoWindow = true;
//// 1
////压缩c:\freezip\free.txt(即文件夹及其下文件freezip\free.txt)
////到c:\freezip\free.rar
strzipPath = "C:\\freezip\\free";//默认压缩方式为 .rar
process1.StartInfo.Arguments = " a -r " + strzipPath + " " + strtxtPath;
WinRar不是系统自带的,是安装系统后再安装的,一般在C:\Program Files\WinRAR
process1.StartInfo.FileName = "WinRAR.exe";
这里指定绝对路径
如process1.StartInfo.FileName = "C:\Program Files\WinRAR
\WinRAR.exe";
process1.StartInfo.FileName = "Notepad.exe";//系统自带的就可以。

p.StartInfo.FileName = {应用程序文件名};
p.StartInfo.Wo