Reputation:
In a program I burn a Cd using ISO Writer, due to this link my code should eject the cd after write because of -e command line, it burns to the cd but doesn't eject it after write, I don't know what's the problem?
//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);
It is the error i get when adding the drive's name in this format:
command = isoWriter.getPath()+" f: -s 16 -e \""+destination.getAbsolutePath()+"\\cd.iso\"";
Upvotes: 0
Views: 264
Reputation: 6063
Try to this by replacing follwing code in your code
command = isoWriter.getPath()+" -s 16 -e \""+destination.getAbsolutePath()+"\\cd.iso\"";
System.out.println(command);
Process writeIso = Runtime.getRuntime().exec(command);
By ..
command = isoburn.exe /q D: \""+destination.getAbsolutePath()+"\\cd.iso\"";
ProcessBuilder builder = new ProcessBuilder("cmd.exe", "/c", command);
builder.redirectErrorStream(true);
Process p = builder.start();
Upvotes: 0
Reputation: 1467
Instead of forming command using + operator you can use 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();
I do not know anything about the library you are using but as per @SantoshShinde I have added drive letter into arguments. You can try skipping it as well to check whether it works.
Upvotes: 1