首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么我的命令行指令不弹出cd?

为什么我的命令行指令不弹出cd?
EN

Stack Overflow用户
提问于 2015-05-11 19:15:18
回答 2查看 211关注 0票数 0

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

代码语言:javascript
复制
//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);

这是我在以这种格式添加驱动器名称时得到的错误:

代码语言:javascript
复制
command = isoWriter.getPath()+" f: -s 16 -e  \""+destination.getAbsolutePath()+"\\cd.iso\"";

EN

回答 2

Stack Overflow用户

发布于 2015-05-11 20:35:16

您可以使用ProcessBuilder,而不是使用+运算符形成命令。

代码语言:javascript
复制
//  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
EN

Stack Overflow用户

发布于 2015-05-11 20:44:01

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

代码语言:javascript
复制
            command = isoWriter.getPath()+" -s 16 -e  \""+destination.getAbsolutePath()+"\\cd.iso\"";
            System.out.println(command);
            Process writeIso = Runtime.getRuntime().exec(command); 

由..

代码语言:javascript
复制
         command = isoburn.exe /q D: \""+destination.getAbsolutePath()+"\\cd.iso\"";
         ProcessBuilder builder = new ProcessBuilder("cmd.exe", "/c", command);
         builder.redirectErrorStream(true);
         Process p = builder.start();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30166246

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档