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 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题