agao1985 2010-11-12 14:24
浏览 287
已采纳

run.exec的使用问题

大家好。本人现在要用到run.exec程序。代码如下[code="java"]
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。。。。。

[/code]
writer是文件的绝对路径。我的意图是编译文件后生成swf文件后下载。但是现在不知道怎么回事总是卡在p.waitFor();中。我本来是要打算用这个来控制文件生成后在下载的,要不然总报找不到文件异常。但是不知道这个用法能不能控制。再者怎么调试run.exec命令啊。我现在根本不知道命令执行没执行。执行到哪了,反正是没成功。有这方面经验的朋友麻烦帮解答下。谢谢

  • 写回答

1条回答 默认 最新

  • 邹锐 2010-11-12 16:44
    关注

    给你一个之前写的方法:
    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();
    }[[/code]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器