问题描述
大家好。本人现在要用到run.exec程序。代码如下String commond = "mxmlc "+writer; Runtime run = Runtime.getRuntime(); try { String[] cmd = new String[4]; cmd[0] = "cmd"; cmd[1] = "c:"; cmd[2] = "cd Program Files/Adobe/Flex Builder 3 Plug-in/sdks/3.2.0/bin "; cmd[3]=commond; Process p = run.exec(cmd[0]); int existValue= p.waitFor(); System.out.println(existValue); //download。。。。。writer是文件的绝对路径。我的意图是编译文件后生成swf文件后下载。但是现在不知道怎么回事总是卡在p.waitFor();中。我本来是要打算用这个来控制文件生成后在下载的,要不然总报找不到文件异常。但是不知道这个用法能不能控制。再者怎么调试run.exec命令啊。我现在根本不知道命令执行没执行。执行到哪了,反正是没成功。有这方面经验的朋友麻烦帮解答下。谢谢
解决方案
给你一个之前写的方法:code="java"]/** * PDF轉換為SWF * @param sourcePath 源文件路径 * @param destPath 目标文件路径 * @param fileName * @return * @throws IOException */public static synchronized int convertPDF2SWF(String projctPath, String sourcePath, String destPath, String fileName) throws IOException {File dest = new File(destPath); if(!dest.exists()) dest.mkdirs(); File source = new File(sourcePath); if(!source.exists()) return 0; String command = ""; //判斷當前的操作系統以調用不同的命令 String osType = System.getProperty("os.name"); if(osType.toLowerCase().indexOf("windows") != -1) command = projctPath+File.separator+"software"+File.separator+"SWFTools"+File.separator+"pdf2swf -o "+destPath+fileName+" -z -B "+projctPath+File.separator+"software"+File.separator+"SWFTools"+File.separator+"rfxview.swf -s flashversion=9 -s -t "+sourcePath+" -s languagedir="+projctPath+File.separator+"software"+File.separator+"xpdf-chinese-simplified"; else command = "/usr/local/bin/pdf2swf -o " + destPath + fileName + " -z -B /usr/local/share/swftools/swfs/rfxview.swf -s flashversion=7 -t " + sourcePath; Process process = Runtime.getRuntime().exec(command); BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream())); while(br.readLine() != null); try { process.waitFor(); } catch (InterruptedException e) { e.printStackTrace(); } return process.exitValue();}[