0

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\"";

enter image description here

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140

2 Answers2

1

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.

Sachin Gorade
  • 1,427
  • 12
  • 32
  • I added the error when using either your code or this one in my question: command = isoWriter.getPath()+" -s 16 -e \""+destination.getAbsolutePath()+"\\cd.iso\""; –  May 12 '15 at 05:25
0

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();
Santosh Shinde
  • 6,045
  • 7
  • 44
  • 68
  • refer this http://tweaks.com/windows/48619/how-to-burn-cd-and-dvd-images-iso-files-from-the-command-line/ – Santosh Shinde May 11 '15 at 12:55
  • I added the error i get using your code to my question –  May 12 '15 at 05:27
  • you need to add your recordable drive is F in your command , command = isoWriter.getPath()+" -s 16 f: -e \""+destination.getAbsolutePath()+"\\cd.iso\""; – Santosh Shinde May 12 '15 at 06:08
  • I added the drive' name and there is an erro which I added it in my question! –  May 12 '15 at 06:18
  • please read this , may be this is useful for you http://superuser.com/questions/712271/is-it-possible-to-burn-an-iso-image-to-a-dvd-using-cmd-in-windows-7-or-8 – Santosh Shinde May 12 '15 at 06:25
  • use this command ,, command = isoburn.exe /q D: \""+destination.getAbsolutePath()+"\\cd.iso\"" here D: is [the CD/DVD writing drive] – Santosh Shinde May 12 '15 at 06:31