Process.Start的参数问题

hamburger521 2008-07-24 02:20:17
Process.Start(processID, UserID.Text.Trim() + " " + strUserPost.ToString() + " " + strSessionId.ToString() + " "
+ strPassWord.ToString() + " \"" + strLoginTime.ToString() + "\" " + this.ExecPlace.Text + " "
+ this.DBIns.Text + " " + this.QChikuCode.Text + " " + this.Filler1.Text + " " + this.Filler2.Text );
我用这个方法启动一个exe
但是第二个参数的字符串传到exe的main里回变成string[]
如果字符串中的几个值为空值的话
数组里就没有这个元素了
我还想让空值的也作为一个元素存放在数组里
怎么办?
...全文
637 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
hamburger521 2008-07-24
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 wangpanli 的回复:]
将每一个参数用引号引起来。比如:

C# code

string arg1 = "aa";
string arg2;
string arg3 = "cc";

string args = "\"" + arg1 + "\" \"" + arg2 + "\" \"" + arg3 + "\"";

Process.Start(processID, args);




这样,在程序processID中就会得到3个参数(虽然arg2是空串)。
[/Quote]
给分
PenleyWang 2008-07-24
  • 打赏
  • 举报
回复
其实在命令行(cmd)中,当路径中间有空格时,为了让程序认为是一个参数就使用了引号。这里是一个道理。
PenleyWang 2008-07-24
  • 打赏
  • 举报
回复
将每一个参数用引号引起来。比如:


string arg1 = "aa";
string arg2;
string arg3 = "cc";

string args = "\"" + arg1 + "\" \"" + arg2 + "\" \"" + arg3 + "\"";

Process.Start(processID, args);


这样,在程序processID中就会得到3个参数(虽然arg2是空串)。
hamburger521 2008-07-24
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 hamburger521 的回复:]
Process.Start(processID, UserID.Text.Trim() + ";" + strUserPost.ToString() + ";" + strSessionId.ToString() + ";"
+ " \"" + strLoginTime.ToString() + "\"; " + this.FolderId.Text + "; " + this.ExecPlace.Text + "; "
+ this.DBIns.Text + "; " + this.QChikuCode.Text + "; " + this.Filler1.Text + "; " + this.Filler2.Text );
加;不行啊,出来数组里面的每个字符串都带;…
[/Quote]
这样是最终出来的数组里就一个元素
把这些字符用,分开了
原来的空格分开的方法可以把它们自动转化成数组里的各个值
hamburger521 2008-07-24
  • 打赏
  • 举报
回复
这个字符串变成数组是内部自动做的
hamburger521 2008-07-24
  • 打赏
  • 举报
回复
Process.Start(processID, UserID.Text.Trim() + ";" + strUserPost.ToString() + ";" + strSessionId.ToString() + ";"
+ " \"" + strLoginTime.ToString() + "\"; " + this.FolderId.Text + "; " + this.ExecPlace.Text + "; "
+ this.DBIns.Text + "; " + this.QChikuCode.Text + "; " + this.Filler1.Text + "; " + this.Filler2.Text );
加;不行啊,出来数组里面的每个字符串都带;了
而且空值还是排除掉了
北京的雾霾天 2008-07-24
  • 打赏
  • 举报
回复
把空格换成逗号试试看。

Process.Start(processID, UserID.Text.Trim() + "," + strUserPost.ToString() + "," + strSessionId.ToString() + ","
+ strPassWord.ToString() + ",\"" + strLoginTime.ToString() + "\"," + this.ExecPlace.Text + ","
+ this.DBIns.Text + "," + this.QChikuCode.Text + "," + this.Filler1.Text + "," + this.Filler2.Text);
hamburger521 2008-07-24
  • 打赏
  • 举报
回复
我试试用;号好使不
hongqi162 2008-07-24
  • 打赏
  • 举报
回复
既然空格你把它当成一个元素怎么还能使用它来做分割符呢,选个别的吧比如逗号或分号
cpio 2008-07-24
  • 打赏
  • 举报
回复
参数应该用引号引起来
shulin_1217 2008-07-24
  • 打赏
  • 举报
回复
类似这样,组合路径看看有没有问题
shulin_1217 2008-07-24
  • 打赏
  • 举报
回复
string ss = System.Windows.Forms.Application.StartupPath + "\\****.exe";
System.Diagnostics.ProcessStartInfo Info = new System.Diagnostics.ProcessStartInfo();
Info.FileName = ss;
System.Diagnostics.Process Proc;
Proc = System.Diagnostics.Process.Start(Info);
ericzhangbo1982111 2008-07-24
  • 打赏
  • 举报
回复
你用;来分隔
在你的exe里面按照;来拆分就可以

或者用\"来相加

110,545

社区成员

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

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

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