JAVA 执行CMD,路径含有空格的解决方案

方案1.
public void startSeleniumServer(String params) {
		  String libPath="C:\\Program Files\\Cisco WebEx\\MagicBoat\\Lib";  
File f = new File(libPath);   
command   ="java -jar selenium-server-standalone.jar";  
Process p = Runtime.getRuntime().exec(command, null, new File(libPath));  	  
.....	
}  

方案2:
cd 到当前目录
用debug quit命令得到转译后的目录,然后执行转译后的路径也可。

方案3.
String cmd = "cipher /e /a C:\\Program Files\\xxxx.properties";
Runtime.getRuntime().exec(cmd);


这样是无法执行,需要在空格的前后加上双引号,而不是在整个路径的前后加双引号.如下:
String cmd = "cipher /e /a "+ "\"" + "C:\\Program Files" +  "\""    "\\xxxx.properties";   
Runtime.getRuntime().exec(cmd);

这段命令是对NTFS分区上的文件进行EFS加密;
还有就是注意java中双引号,
单引号的打法双引号:String aaa = "\"\"";
单引号 String bbb = "\"";


String file = "c:\\Program Files\\Internet Explorer\\iexplore.exe";
		String sysPath = "C:\\Program Files\\SystemVue2013.01\\bin\\SystemVue.exe";
		String sysFile = " c:\\glaway\\tt.wsv";
		String hfssPath = "C:\\AnsysHFSS15\\HFSS15.0\\Win64\\hfss.exe";
		String hfssFile = " c:\\glaway\\Project2.hfss";
		String command = "cmd /c start "+hfssPath.replaceAll(" ","\" \"")+hfssFile;

猜你喜欢

转载自duanfei.iteye.com/blog/2098256