c#中如何调用一个带参数的命令行
System.Security.SecureString password = new System.Security.SecureString(); char[] pass = { 'w', 'd', 'o', 'w', 'n', 'e', 'r'}; for (int i = 0; i < pass.Length; i++)
{ password.AppendChar(pass[i]); } password.MakeReadOnly();
Process p = new Process(); p.Start("MHIdentificationFileSessionSample.exe", "wdowner", '"password"', "ExampleContent.mpg");执行MHIdentificationFileSessionSample.exe命令行,带参数用户名:wdowner 密码:password 第三个参数是ExampleContent.mpg。
这样做对吗
System.Security.SecureString password = new System.Security.SecureString(); char[] pass = { 'w', 'd', 'o', 'w', 'n', 'e', 'r'}; for (int i = 0; i < pass.Length; i++)
{ password.AppendChar(pass[i]); } password.MakeReadOnly();
Process p = new Process(); p.Start("MHIdentificationFileSessionSample.exe", "wdowner", '"password"', "ExampleContent.mpg");执行MHIdentificationFileSessionSample.exe命令行,带参数用户名:wdowner 密码:password 第三个参数是ExampleContent.mpg。
这样做对吗
p.StartInfo = new ProcessStartInfo(filename, argsments);
p.Start();
这样对吗
Process p = new Process();
p.Start();
wdowner,password,ExampleContent.mpg 分别是用户名,密码,一个媒体文件本来是 命令行运行
MHIdentificationFileSessionSample.exe wdowner wdowner ExampleContent.mpg
现在我要在c#里用语句执行这个命令行,如何写
MHIdentificationFileSessionSample.exe
三个参数 wdowner wdowner ExampleContent.mpg
现在我在c#里用语句执行这个命令行,如何用ProcessStartInfo写
startInfo.FileName = @"C:\\Program Files\\MediaHedge\\MHSDK\MHIdentificationFileSessionExample\\win\\MHIdentificationFileSessionSample.exe";
//参数用空格分开
startInfo.Arguments = @"wdowner"+" "+"wdowner"+" "+"C:\\Program Files\\MediaHedge\\MHSDK\\MHIdentificationFileSessionExample\\win\\ExampleContent.mpg";
System.Diagnostics.Process.Start(startInfo); z怎么还是不行呢?
楼上的代码肉眼看不出问题
如果可以再检测Arguments属性里拼写
C:\\Program Files\\MediaHedge\\MHSDK\MHIdentificationFileSessionExample\\win\\MHIdentificationFileSessionSample.exe wdowner wdowner C:\\Program Files\\MediaHedge\\MHSDK\\MHIdentificationFileSessionExample\\win\\ExampleContent.mpg执行成功。但是
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.FileName = @"C:\\Program Files\\MediaHedge\\MHSDK\MHIdentificationFileSessionExample\\win\\MHIdentificationFileSessionSample.exe";
//参数用空格分开
startInfo.Arguments = @"wdowner"+" "+"wdowner"+" "+"C:\\Program Files\\MediaHedge\\MHSDK\\MHIdentificationFileSessionExample\\win\\ExampleContent.mpg";
System.Diagnostics.Process.Start(startInfo); 不行。报错说MHIdentificationFileSessionSample.exe的用法错误
为什么?
我的Arguments 组合错了吗?
我的组合错了吗?
using System.Diagnostics;namespace ClassB
{
class B
{
public static void Main(string [] args)
{
if(args!=null)
Console.WriteLine("有{0}个命令行参数",args.Length);
Console.ReadKey();
}
}
}可以正确输出参数的个数。