System.Diagnostics.Process proc;
proc = System.Diagnostics.Process.Start(@"C:\wxy.bat iT sT");
proc.WaitForExit();
带两个参数为什么不行啊?
12 个解决方案
#1
up
#2
proc = System.Diagnostics.Process.Start(@"C:\wxy.bat", "iT sT");
#3
我试过了,这样不行啊
#4
老大,关键是看你wxy.bat文件是否接受参数?
#5
肯定接受啊,我直接在命令行执行 c:\wxy.bat 1 2 就可以啊
#6
//试试里面的方法,
using System;
using System.Diagnostics;
namespace Zhzuo
{
/// <summary>
/// CmdUtility 的摘要说明。
/// </summary>
public class CmdUtility
{
/// <summary>
/// 执行cmd.exe命令
/// </summary>
/// <param name="commandText">命令文本</param>
/// <returns>命令输出文本</returns>
public static string ExeCommand(string commandText)
{
return ExeCommand(new string []{commandText});
}
/// <summary>
/// 执行多条cmd.exe命令
/// </summary>
/// <param name="commandArray">命令文本数组</param>
/// <returns>命令输出文本</returns>
public static string ExeCommand(string [] commandTexts)
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
string strOutput = null;
try
{
p.Start();
foreach(string item in commandTexts)
{
p.StandardInput.WriteLine(item);
}
p.StandardInput.WriteLine("exit");
strOutput = p.StandardOutput.ReadToEnd();
p.WaitForExit();
p.Close();
}
catch(Exception e)
{
strOutput = e.Message;
}
return strOutput;
}
/// <summary>
/// 启动外部Windows应用程序,隐藏程序界面
/// </summary>
/// <param name="appName">应用程序路径名称</param>
/// <returns>true表示成功,false表示失败</returns>
public static bool StartApp(string appName)
{
return StartApp(appName,ProcessWindowStyle.Hidden);
}
/// <summary>
/// 启动外部应用程序
/// </summary>
/// <param name="appName">应用程序路径名称</param>
/// <param name="style">进程窗口模式</param>
/// <returns>true表示成功,false表示失败</returns>
public static bool StartApp(string appName,ProcessWindowStyle style)
{
return StartApp(appName,null,style);
}
/// <summary>
/// 启动外部应用程序,隐藏程序界面
/// </summary>
/// <param name="appName">应用程序路径名称</param>
/// <param name="arguments">启动参数</param>
/// <returns>true表示成功,false表示失败</returns>
public static bool StartApp(string appName,string arguments)
{
return StartApp(appName,arguments,ProcessWindowStyle.Hidden);
}
/// <summary>
/// 启动外部应用程序
/// </summary>
/// <param name="appName">应用程序路径名称</param>
/// <param name="arguments">启动参数</param>
/// <param name="style">进程窗口模式</param>
/// <returns>true表示成功,false表示失败</returns>
public static bool StartApp(string appName,string arguments,ProcessWindowStyle style)
{
bool blnRst = false;
Process p = new Process();
p.StartInfo.FileName = appName;//exe,bat and so on
p.StartInfo.WindowStyle = style;
p.StartInfo.Arguments = arguments;
try
{
p.Start();
p.WaitForExit();
p.Close();
blnRst = true;
}
catch
{
}
return blnRst;
}
}
}
using System;
using System.Diagnostics;
namespace Zhzuo
{
/// <summary>
/// CmdUtility 的摘要说明。
/// </summary>
public class CmdUtility
{
/// <summary>
/// 执行cmd.exe命令
/// </summary>
/// <param name="commandText">命令文本</param>
/// <returns>命令输出文本</returns>
public static string ExeCommand(string commandText)
{
return ExeCommand(new string []{commandText});
}
/// <summary>
/// 执行多条cmd.exe命令
/// </summary>
/// <param name="commandArray">命令文本数组</param>
/// <returns>命令输出文本</returns>
public static string ExeCommand(string [] commandTexts)
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
string strOutput = null;
try
{
p.Start();
foreach(string item in commandTexts)
{
p.StandardInput.WriteLine(item);
}
p.StandardInput.WriteLine("exit");
strOutput = p.StandardOutput.ReadToEnd();
p.WaitForExit();
p.Close();
}
catch(Exception e)
{
strOutput = e.Message;
}
return strOutput;
}
/// <summary>
/// 启动外部Windows应用程序,隐藏程序界面
/// </summary>
/// <param name="appName">应用程序路径名称</param>
/// <returns>true表示成功,false表示失败</returns>
public static bool StartApp(string appName)
{
return StartApp(appName,ProcessWindowStyle.Hidden);
}
/// <summary>
/// 启动外部应用程序
/// </summary>
/// <param name="appName">应用程序路径名称</param>
/// <param name="style">进程窗口模式</param>
/// <returns>true表示成功,false表示失败</returns>
public static bool StartApp(string appName,ProcessWindowStyle style)
{
return StartApp(appName,null,style);
}
/// <summary>
/// 启动外部应用程序,隐藏程序界面
/// </summary>
/// <param name="appName">应用程序路径名称</param>
/// <param name="arguments">启动参数</param>
/// <returns>true表示成功,false表示失败</returns>
public static bool StartApp(string appName,string arguments)
{
return StartApp(appName,arguments,ProcessWindowStyle.Hidden);
}
/// <summary>
/// 启动外部应用程序
/// </summary>
/// <param name="appName">应用程序路径名称</param>
/// <param name="arguments">启动参数</param>
/// <param name="style">进程窗口模式</param>
/// <returns>true表示成功,false表示失败</returns>
public static bool StartApp(string appName,string arguments,ProcessWindowStyle style)
{
bool blnRst = false;
Process p = new Process();
p.StartInfo.FileName = appName;//exe,bat and so on
p.StartInfo.WindowStyle = style;
p.StartInfo.Arguments = arguments;
try
{
p.Start();
p.WaitForExit();
p.Close();
blnRst = true;
}
catch
{
}
return blnRst;
}
}
}
#7
private System.Diagnostics.ProcessStartInfo Info = new System.Diagnostics.ProcessStartInfo();
private System.Diagnostics.Process Proc = new System.Diagnostics.Process();
Info.FileName = "命令";
Info.Arguments = "参数";
Proc = System.Diagnostics.Process.Start(Info);
private System.Diagnostics.Process Proc = new System.Diagnostics.Process();
Info.FileName = "命令";
Info.Arguments = "参数";
Proc = System.Diagnostics.Process.Start(Info);
#8
直接用api函数试试
#9
System.Diagnostics.ProcessStartInfo psi =
new System.Diagnostics.ProcessStartInfo();
psi.FileName = @"C:\WINDOWS\system32\cmd.exe";
psi.Arguments = "/c c:\wxy.bat 1 2";
psi.WindowStyle=System.Diagnostics.ProcessWindowStyle.Hidden;
System.Diagnostics.Process.Start(psi);
我在给CSDN上朋友的回贴,和你这差不多:
http://community.csdn.net/Expert/TopicView.asp?id=4128635
new System.Diagnostics.ProcessStartInfo();
psi.FileName = @"C:\WINDOWS\system32\cmd.exe";
psi.Arguments = "/c c:\wxy.bat 1 2";
psi.WindowStyle=System.Diagnostics.ProcessWindowStyle.Hidden;
System.Diagnostics.Process.Start(psi);
我在给CSDN上朋友的回贴,和你这差不多:
http://community.csdn.net/Expert/TopicView.asp?id=4128635
#10
System.Diagnostics.Process proc;
proc = System.Diagnostics.Process.Start(@"cmd /c C:\wxy.bat iT sT");
proc.WaitForExit();
proc = System.Diagnostics.Process.Start(@"cmd /c C:\wxy.bat iT sT");
proc.WaitForExit();
#11
mark
#12
Thanks!
#1
up
#2
proc = System.Diagnostics.Process.Start(@"C:\wxy.bat", "iT sT");
#3
我试过了,这样不行啊
#4
老大,关键是看你wxy.bat文件是否接受参数?
#5
肯定接受啊,我直接在命令行执行 c:\wxy.bat 1 2 就可以啊
#6
//试试里面的方法,
using System;
using System.Diagnostics;
namespace Zhzuo
{
/// <summary>
/// CmdUtility 的摘要说明。
/// </summary>
public class CmdUtility
{
/// <summary>
/// 执行cmd.exe命令
/// </summary>
/// <param name="commandText">命令文本</param>
/// <returns>命令输出文本</returns>
public static string ExeCommand(string commandText)
{
return ExeCommand(new string []{commandText});
}
/// <summary>
/// 执行多条cmd.exe命令
/// </summary>
/// <param name="commandArray">命令文本数组</param>
/// <returns>命令输出文本</returns>
public static string ExeCommand(string [] commandTexts)
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
string strOutput = null;
try
{
p.Start();
foreach(string item in commandTexts)
{
p.StandardInput.WriteLine(item);
}
p.StandardInput.WriteLine("exit");
strOutput = p.StandardOutput.ReadToEnd();
p.WaitForExit();
p.Close();
}
catch(Exception e)
{
strOutput = e.Message;
}
return strOutput;
}
/// <summary>
/// 启动外部Windows应用程序,隐藏程序界面
/// </summary>
/// <param name="appName">应用程序路径名称</param>
/// <returns>true表示成功,false表示失败</returns>
public static bool StartApp(string appName)
{
return StartApp(appName,ProcessWindowStyle.Hidden);
}
/// <summary>
/// 启动外部应用程序
/// </summary>
/// <param name="appName">应用程序路径名称</param>
/// <param name="style">进程窗口模式</param>
/// <returns>true表示成功,false表示失败</returns>
public static bool StartApp(string appName,ProcessWindowStyle style)
{
return StartApp(appName,null,style);
}
/// <summary>
/// 启动外部应用程序,隐藏程序界面
/// </summary>
/// <param name="appName">应用程序路径名称</param>
/// <param name="arguments">启动参数</param>
/// <returns>true表示成功,false表示失败</returns>
public static bool StartApp(string appName,string arguments)
{
return StartApp(appName,arguments,ProcessWindowStyle.Hidden);
}
/// <summary>
/// 启动外部应用程序
/// </summary>
/// <param name="appName">应用程序路径名称</param>
/// <param name="arguments">启动参数</param>
/// <param name="style">进程窗口模式</param>
/// <returns>true表示成功,false表示失败</returns>
public static bool StartApp(string appName,string arguments,ProcessWindowStyle style)
{
bool blnRst = false;
Process p = new Process();
p.StartInfo.FileName = appName;//exe,bat and so on
p.StartInfo.WindowStyle = style;
p.StartInfo.Arguments = arguments;
try
{
p.Start();
p.WaitForExit();
p.Close();
blnRst = true;
}
catch
{
}
return blnRst;
}
}
}
using System;
using System.Diagnostics;
namespace Zhzuo
{
/// <summary>
/// CmdUtility 的摘要说明。
/// </summary>
public class CmdUtility
{
/// <summary>
/// 执行cmd.exe命令
/// </summary>
/// <param name="commandText">命令文本</param>
/// <returns>命令输出文本</returns>
public static string ExeCommand(string commandText)
{
return ExeCommand(new string []{commandText});
}
/// <summary>
/// 执行多条cmd.exe命令
/// </summary>
/// <param name="commandArray">命令文本数组</param>
/// <returns>命令输出文本</returns>
public static string ExeCommand(string [] commandTexts)
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
string strOutput = null;
try
{
p.Start();
foreach(string item in commandTexts)
{
p.StandardInput.WriteLine(item);
}
p.StandardInput.WriteLine("exit");
strOutput = p.StandardOutput.ReadToEnd();
p.WaitForExit();
p.Close();
}
catch(Exception e)
{
strOutput = e.Message;
}
return strOutput;
}
/// <summary>
/// 启动外部Windows应用程序,隐藏程序界面
/// </summary>
/// <param name="appName">应用程序路径名称</param>
/// <returns>true表示成功,false表示失败</returns>
public static bool StartApp(string appName)
{
return StartApp(appName,ProcessWindowStyle.Hidden);
}
/// <summary>
/// 启动外部应用程序
/// </summary>
/// <param name="appName">应用程序路径名称</param>
/// <param name="style">进程窗口模式</param>
/// <returns>true表示成功,false表示失败</returns>
public static bool StartApp(string appName,ProcessWindowStyle style)
{
return StartApp(appName,null,style);
}
/// <summary>
/// 启动外部应用程序,隐藏程序界面
/// </summary>
/// <param name="appName">应用程序路径名称</param>
/// <param name="arguments">启动参数</param>
/// <returns>true表示成功,false表示失败</returns>
public static bool StartApp(string appName,string arguments)
{
return StartApp(appName,arguments,ProcessWindowStyle.Hidden);
}
/// <summary>
/// 启动外部应用程序
/// </summary>
/// <param name="appName">应用程序路径名称</param>
/// <param name="arguments">启动参数</param>
/// <param name="style">进程窗口模式</param>
/// <returns>true表示成功,false表示失败</returns>
public static bool StartApp(string appName,string arguments,ProcessWindowStyle style)
{
bool blnRst = false;
Process p = new Process();
p.StartInfo.FileName = appName;//exe,bat and so on
p.StartInfo.WindowStyle = style;
p.StartInfo.Arguments = arguments;
try
{
p.Start();
p.WaitForExit();
p.Close();
blnRst = true;
}
catch
{
}
return blnRst;
}
}
}
#7
private System.Diagnostics.ProcessStartInfo Info = new System.Diagnostics.ProcessStartInfo();
private System.Diagnostics.Process Proc = new System.Diagnostics.Process();
Info.FileName = "命令";
Info.Arguments = "参数";
Proc = System.Diagnostics.Process.Start(Info);
private System.Diagnostics.Process Proc = new System.Diagnostics.Process();
Info.FileName = "命令";
Info.Arguments = "参数";
Proc = System.Diagnostics.Process.Start(Info);
#8
直接用api函数试试
#9
System.Diagnostics.ProcessStartInfo psi =
new System.Diagnostics.ProcessStartInfo();
psi.FileName = @"C:\WINDOWS\system32\cmd.exe";
psi.Arguments = "/c c:\wxy.bat 1 2";
psi.WindowStyle=System.Diagnostics.ProcessWindowStyle.Hidden;
System.Diagnostics.Process.Start(psi);
我在给CSDN上朋友的回贴,和你这差不多:
http://community.csdn.net/Expert/TopicView.asp?id=4128635
new System.Diagnostics.ProcessStartInfo();
psi.FileName = @"C:\WINDOWS\system32\cmd.exe";
psi.Arguments = "/c c:\wxy.bat 1 2";
psi.WindowStyle=System.Diagnostics.ProcessWindowStyle.Hidden;
System.Diagnostics.Process.Start(psi);
我在给CSDN上朋友的回贴,和你这差不多:
http://community.csdn.net/Expert/TopicView.asp?id=4128635
#10
System.Diagnostics.Process proc;
proc = System.Diagnostics.Process.Start(@"cmd /c C:\wxy.bat iT sT");
proc.WaitForExit();
proc = System.Diagnostics.Process.Start(@"cmd /c C:\wxy.bat iT sT");
proc.WaitForExit();
#11
mark
#12
Thanks!