为什么我的命令行指令不会弹出CD?

时间:2015-05-11 11:15:18

标签: java command-line cd-rom cd-burning

在一个程序中我使用ISO Writer刻录了一个Cd,由于这个link因为-e命令行我的代码应该在写入后弹出cd,它会刻录到cd但是在写入后不会弹出它,我不知道是什么问题?

//Library that use to create iso file
File mkisofs = new File("lib/cdrtools/mkisofs.exe");

//The root of file that we want to write on DVD
File source = new File(new ProductUtil().getProductDir()+ "\\output\\Autorun");

//Destination that the iso file will be save on it.
File destination = source.getParentFile();

//Library that use to write iso file
File isoWriter = new File("lib/isowriter/ISOWriter.exe");


String command = mkisofs.getPath()+" -UDF -o \'"+destination.getAbsolutePath()+"\\cd.iso\' \'"+source.getAbsolutePath()+"\'";
Process createIso = Runtime.getRuntime().exec(command);
BufferedReader reader = new BufferedReader(new InputStreamReader(createIso.getErrorStream()));

String line = "";
String all = "";

while((line = reader.readLine()) != null) {
    all += line+"\r\n";
}

if(createIso.waitFor() != 0) {
    JOptionPane.showMessageDialog(null, all,"Error on creating ISO file: ("+createIso.waitFor()+")",JOptionPane.ERROR_MESSAGE);
    return null;
}

command = isoWriter.getPath()+" -s 16 -e  \""+destination.getAbsolutePath()+"\\cd.iso\"";
System.out.println(command);
Process writeIso = Runtime.getRuntime().exec(command);

这是以这种格式添加驱动器名称时出现的错误:

command = isoWriter.getPath()+" f: -s 16 -e  \""+destination.getAbsolutePath()+"\\cd.iso\"";

enter image description here

2 个答案:

答案 0 :(得分:1)

您可以使用ProcessBuilder来代替使用+运算符创建命令。

//  Library that use to create iso file
                File mkisofs = new File("lib/cdrtools/mkisofs.exe");
                //  The root of file that we want to write on DVD
                File source = new File(new ProductUtil().getProductDir()+ "\\output\\Autorun");
                //  Destination that the iso file will be save on it.
                File destination = source.getParentFile();
                //  Library that use to write iso file
                File isoWriter = new File("lib/isowriter/ISOWriter.exe");
                String command[] = {mkisofs.getPath(), "-UDF", "-o", destination.getAbsolutePath()+"\\cd.iso", source.getAbsolutePath() };
                 Process createIso = new ProcessBuilder(command).start();
            BufferedReader reader = new BufferedReader(new InputStreamReader(createIso.getErrorStream()));
            String line = "";
            String all = "";
            while((line = reader.readLine()) != null){
                all += line+"\r\n";
            }
            if(createIso.waitFor() != 0){
                JOptionPane.showMessageDialog(null, all,"Error on creating ISO file: ("+createIso.waitFor()+")",JOptionPane.ERROR_MESSAGE);
                return null;
            }
            command = {isoWriter.getPath(), "-s", "16", "E:", "-e",  destination.getAbsolutePath()+"\\cd.iso"};
            System.out.println(command);
            Process writeIso = new ProcessBuilder(command).start();

我对您使用的库一无所知,但根据@SantoshShinde,我已将驱动器号添加到参数中。您也可以尝试跳过它来检查它是否有效。

答案 1 :(得分:0)

通过替换代码中的以下代码来尝试这一点

            command = isoWriter.getPath()+" -s 16 -e  \""+destination.getAbsolutePath()+"\\cd.iso\"";
            System.out.println(command);
            Process writeIso = Runtime.getRuntime().exec(command); 

通过..

         command = isoburn.exe /q D: \""+destination.getAbsolutePath()+"\\cd.iso\"";
         ProcessBuilder builder = new ProcessBuilder("cmd.exe", "/c", command);
         builder.redirectErrorStream(true);
         Process p = builder.start();