c# 中Process p = new Process()问题

ssyyo_bj 2009-08-13 09:26:03
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。


这样做对吗
...全文
1045 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
ssyyo_bj 2009-08-13
  • 打赏
  • 举报
回复
startInfo.Arguments = @"wdowner"+" "+"wdowner"+" "+"C:\\Program Files\\MediaHedge\\MHSDK\\MHIdentificationFileSessionExample\\win\\ExampleContent.mpg";


我的组合错了吗?
ssyyo_bj 2009-08-13
  • 打赏
  • 举报
回复
命令行执行:
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 组合错了吗?
LutzMark 2009-08-13
  • 打赏
  • 举报
回复
你在cmd里执行同样的命令可以么?
楼上的代码肉眼看不出问题
如果可以再检测Arguments属性里拼写
ssyyo_bj 2009-08-13
  • 打赏
  • 举报
回复
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);

z怎么还是不行呢?
ssyyo_bj 2009-08-13
  • 打赏
  • 举报
回复
能具体些吗?

应用程序:
MHIdentificationFileSessionSample.exe
三个参数 wdowner wdowner ExampleContent.mpg
现在我在c#里用语句执行这个命令行,如何用ProcessStartInfo写


dancingbit 2009-08-13
  • 打赏
  • 举报
回复
使用ProcessStartInfo类,有一个Arguements属性,用于向应用程序提供运行参数。
ssyyo_bj 2009-08-13
  • 打赏
  • 举报
回复
我现在要运行一个MHIdentificationFileSessionSample.exe命令,同时带三个参数:
wdowner,password,ExampleContent.mpg 分别是用户名,密码,一个媒体文件



本来是 命令行运行
MHIdentificationFileSessionSample.exe wdowner wdowner ExampleContent.mpg
现在我要在c#里用语句执行这个命令行,如何写

chaozi_249 2009-08-13
  • 打赏
  • 举报
回复
还没有碰到过这样的问题, 关注下 ,以前只是
Process p = new Process();
p.Start();
dancingbit 2009-08-13
  • 打赏
  • 举报
回复
这个重载,中间的两个参数是程序运行时所需要的域用户名和密码,不是提供给程序的参数。
ssyyo_bj 2009-08-13
  • 打赏
  • 举报
回复
Process p = new Process();

p.Start("MHIdentificationFileSessionSample.exe", "wdowner",password, "ExampleContent.mpg");


这样对吗
lunasea0_0 2009-08-13
  • 打赏
  • 举报
回复
Process.Start(filename, user, password, domain)
北京的雾霾天 2009-08-13
  • 打赏
  • 举报
回复
Process p = new Process();
p.StartInfo = new ProcessStartInfo(filename, argsments);
p.Start();
coconutyf 2009-08-13
  • 打赏
  • 举报
回复
process.Start("MHIdentificationFileSessionSample.exe", " wdowner wdowner ExampleContent.mpg ");
flyerwing 2009-08-13
  • 打赏
  • 举报
回复
Process.Start(filename, user, password, domain)
dancingbit 2009-08-13
  • 打赏
  • 举报
回复
这样的组合应该是没有错,测试的结果是Arguements的值会按照空格分割成字符串数组。

比如:

using System;
using System.Diagnostics;

namespace ClassB
{
class B
{
public static void Main(string [] args)
{
if(args!=null)
Console.WriteLine("有{0}个命令行参数",args.Length);
Console.ReadKey();
}
}
}


可以正确输出参数的个数。

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧