c# 命令行参数 问题?求教!!

mzy939216 2009-12-29 10:56:35
public void CalcRCCM2000()
{
string path = System.Windows.Forms.Application.StartupPath;
System.Diagnostics.Process.Start(path +
@"\RCCM2000.exe tan\rccm_class_1_tan2.spp tan\rccm_class_1_tan2.prf tan\rccm_class_1_tan2.fre tan\library_si.xml tan\rccm_class_1_tan2.r2k");
}

这是通过winform调用RCCM2000.exe的代码!用来传入命令行参数!


static void Main(string[] args)
{
RCCM2000 rccm = new RCCM2000();
rccm.Calculate(args[0], args[1], args[2], args[3], args[4]);
}

这是RCCM2000.exe的入口,接收命令行参数!

运行时下面这行语句出错:
System.Diagnostics.Process.Start(path +
@"\RCCM2000.exe tan\rccm_class_1_tan2.spp tan\rccm_class_1_tan2.prf tan\rccm_class_1_tan2.fre tan\library_si.xml tan\rccm_class_1_tan2.r2k");
}

提示:未处理Win32Exception 系统找不到指定的文件。
请高手帮忙分析一下原因!
...全文
127 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
mzy939216 2009-12-29
  • 打赏
  • 举报
回复
我已经解决问题了!
下面是我修改后的代码!!
public void CalcRCCM2000()
{
string projectPath = System.Windows.Forms.Application.StartupPath;
string filePath = System.Environment.CurrentDirectory;
System.Diagnostics.Process.Start(projectPath + @"\RCCM2000.exe " + filePath + @"\rccm_class_1_tan2.spp "
+ filePath + @"\rccm_class_1_tan2.prf " + filePath + @"\rccm_class_1_tan2.fre " + filePath + @"\library_si.xml "
+ filePath + @"\rccm_class_1_tan2.r2k");
}
whslovexyp 2009-12-29
  • 打赏
  • 举报
回复
只是想告诉你,调试时取的文件路径和运行时取的文件路径不一样,能不能把你的exe拷贝到和Debug同级的目录上
chuangwan 2009-12-29
  • 打赏
  • 举报
回复
你path+@"\RCCM2000.exe tan\rccm_class_1_tan2.spp tan\rccm_class_1_tan2.prf tan\rccm_class_1_tan2.fre tan\library_si.xml tan\rccm_class_1_tan2.r2k" 的路径是什么?
而你实际要找的文件的路径又是什么? 然后看看它们两者的具体区别。从它们的区别找突破口
mzy939216 2009-12-29
  • 打赏
  • 举报
回复
搞不懂??
tan\rccm_class_1_tan2.spp tan\rccm_class_1_tan2.prf tan\rccm_class_1_tan2.fre tan\library_si.xml tan\rccm_class_1_tan2.r2k
难道这几个都要用完整路径?
mzy939216 2009-12-29
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 lianshaohua 的回复:]
先把path +
@"\RCCM2000.exe tan\rccm_class_1_tan2.spp tan\rccm_class_1_tan2.prf tan\rccm_class_1_tan2.fre tan\library_si.xml tan\rccm_class_1_tan2.r2k"

显示出来,看看文件路径,名是否正确。。。。。。很有可能出在:@"\这里
[/Quote]
就是这个!
F:\工作\IT09023.NPIC.NPPS\Source\NPPS\bin\Debug\RCCM2000.exe tan\rccm_class_1_tan2.spp tan\rccm_class_1_tan2.prf tan\rccm_class_1_tan2.fre tan\library_si.xml tan\rccm_class_1_tan2.r2k

我检查过了,没有任何文件名,路径名的错误!
mzy939216 2009-12-29
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 kensouterry 的回复:]
那你的路径出了点问题
[/Quote]
我用断点单步了一下,得出来的path的value:F:\工作\IT09023.NPIC.NPPS\Source\NPPS\bin\Debug
而我tan文件夹的路径:F:\工作\IT09023.NPIC.NPPS\Source\NPPS\bin\Debug\tan
而RCCM2000.exe在F:\工作\IT09023.NPIC.NPPS\Source\NPPS\bin\Debug里面

路径没有问题啊!!
ztenv 2009-12-29
  • 打赏
  • 举报
回复
先把path +
@"\RCCM2000.exe tan\rccm_class_1_tan2.spp tan\rccm_class_1_tan2.prf tan\rccm_class_1_tan2.fre tan\library_si.xml tan\rccm_class_1_tan2.r2k"


显示出来,看看文件路径,名是否正确。。。。。。很有可能出在:@"\这里
mzy939216 2009-12-29
  • 打赏
  • 举报
回复
我不知道命令行参数的格式写的有没有错误!!
mzy939216 2009-12-29
  • 打赏
  • 举报
回复
请高手们帮帮忙!
kensouterry 2009-12-29
  • 打赏
  • 举报
回复
那你的路径出了点问题
  • 打赏
  • 举报
回复
帮顶
夏脑 2009-12-29
  • 打赏
  • 举报
回复
C# codeSystem.Diagnostics.Process.Start("\""+path +
@"\RCCM2000.exe tan\rccm_class_1_tan2.spp tan\rccm_class_1_tan2.prf tan\rccm_class_1_tan2.fre tan\library_si.xml tan\rccm_class_1_tan2.r2k\"");
}
antony1029 2009-12-29
  • 打赏
  • 举报
回复
jf啦!呵呵
flyerwing 2009-12-29
  • 打赏
  • 举报
回复
得先取的当前路径去找那个东西,或者直接是绝对路径吧
mzy939216 2009-12-29
  • 打赏
  • 举报
回复
在进来一些人,留点言,加点人气啊!!留言就给分

111,123

社区成员

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

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

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