Runtimesh=Runtime.getRuntime();Stringfilepath="\"D:/ProgramFiles/Tencent/QQ/QQProtect/Bin/QQProtect.exe\""sh.exec("cmd.exe/c"+filepath);这样的组合是可以在Myeclipse和导出j...
Runtime sh = Runtime.getRuntime();
String filepath = "\"D:/Program Files/Tencent/QQ/QQProtect/Bin/QQProtect.exe\""
sh.exec("cmd.exe /c "+filepath);
这样的组合是可以在Myeclipse和导出jar文件的时候正常执行的
String filepath = "\"D:/Program Files/Tencent/QQ/QQProtect/Bin/QQProtect.exe\""
sh.exec(filepath);
String filepath2 = "D:/Program Files/Tencent/QQ/QQProtect/Bin/QQProtect.exe" //2
sh.exec(filepath2);
这样两种的组合的话在Myeclipse正常执行但是导出jar后无法执行打开QQ的命令
String filepath2 = "D:/Program Files/Tencent/QQ/QQProtect/Bin/QQProtect.exe" //2
sh.exec("cmd.exe /c "+filepath2);
这样甚至在eclipse中都无法正常执行
试了很多种可能:最后判断是路径原因.
因为有像Program Files这样带有空格的字符..但是奇怪的是我不是已经把他定义成String了吗
难道不是一整句都当成一个字符串来看么?
为什么路径一定要用"cmd.exe /c "+"\"D:/Program Files/Tencent/QQ/QQProtect/Bin/QQProtect.exe\"" 才可以?
String filepath ="D:/Program Files/Tencent/QQ/QQProtect/Bin/QQProtect.exe"
sh.exec(filepath);
像这样直接引用windows下面的路径直接调用就不可以~求解 很乱~
展开