应用场景描述:
java web程序,触发 调用c#写的后台exe程序,发现exe里写的文件找不到。单独在cmd命令行下执行exe没问题;
问题查找:
由于exe里获取文件路径错误导致;
解决方法:
exe中获取程序路径改为:
string pathLog = System.Reflection.Assembly.GetExecutingAssembly().Location;
pathLog = pathLog.Substring(0, pathLog.LastIndexOf(@"")) + "/Log.txt";
附录:java里调exe代码:
@RequestMapping(value="exeTest")
@ResponseBody
public void exeTest() {
String mainExePath ="F:\Trans2Json\Trans2Json.exe",prjid="1",mid="104",modelExePath="",modelParamsPath="",type="",
contourLineExePath="",contourLineParamsPath="";
try {
Process process = Runtime.getRuntime().exec(mainExePath + " All 1 104");
BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
String str;
while(( str = br.readLine()) != null)
{
System.out.println(str);
}
System.out.println("成功");
}catch (Exception e) {
System.out.println("计算失败");
}
}