Java 执行外部程序报1072365564错误问题的解决方法


貌似是环境变量设置不全引起的.
Hi,
I am using new Antenna 1.2.0-beta with Java ME SDK 3.0. I have a problem during preverification. I 'm getting error:

[INFO] Preverification failed (result=-1072365564)
[INFO] ----------------------------------------------------------------
[INFO] Trace
Preverification failed (result=-1072365564)
at de.pleumann.antenna.misc.Utility.preverify(Utility.java:566)

I checked your code and I found the reason. At least I think so. In preverify() method you do:

// prepend java bin path to system PATH calling preverify
String env[] = new String[]{
"PATH=" + java_bin + System.getProperty("path.separator") + System.getenv("PATH")
};
Process proc = Runtime.getRuntime().exec(preverify + " " + arguments, env);

I checked this fragment and if I change exec() method to form without env argument everything works ok:

Process proc = Runtime.getRuntime().exec(preverify + " " + arguments);

Probably you invoke version with env arg, because you want to add proper JAVA folder to PATH.
In my opinion you should pass all the system ENV variables together with modified PATH. Then everything will work.

Map<String, String> map = new HashMap<String, String>(System.getenv());
List<String> list = new ArrayList<String>(maps.size());
for (Entry<String, String> e : map.entrySet()) {
list.add(e.getKey() + "=" + e.getValue());
}
// modify PATH
Process exec = Runtime.getRuntime().exec(cmd, list.toArray(new String[0]));

I found that in my case it was 'SystemRoot' env variable that caused a problem. I think that two args exec(...) method works different than one arg. In one arg, all the system variables are passed to child process, in 2-arg you pass only what you declare in table, so it would be safer to copy all variables to table modify PATH position and pass to exec. This problem may depends on operating system.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值