1

I have two files to be given as an input and I am using Beyond Compare tool Java API to check whether the contents in both the files are same or not.

I want to do this without opening the Beyond Compare window. Below is the code which I am using currently.

ProcessBuilder processBuilder = new ProcessBuilder("C:\\Program Files\\Beyond Compare 4\\BCompare.exe",
            "file1path", "file2path","/qc=bin", "\silent");

    Process ps;
    try {
        ps = processBuilder.start();
        OutputStream os = ps.getOutputStream();
        os.close();

        InputStream inputStream = ps.getInputStream();
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        for (String line = bufferedReader.readLine(); line != null; line = bufferedReader.readLine()) {
        }

        ps.waitFor();
        System.out.println("Exit value :" + ps.exitValue());
    } catch (IOException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

As mentioned here enter link description here, using /silent will not open the window. Despite using /silent, I can still see the window pop up of Beyond Compare tool. Please suggest some work around to achieve the same

BIndu_Madhav
  • 577
  • 1
  • 8
  • 21
  • My suggestion: first try to master calling of the BCompare.exe from Command Line and just after that move to java and call it as an external process – bohuss Mar 30 '17 at 09:03
  • Also it seems you are using backslash instead of slash for windows command - replace \silent with /silent in your last argument when creating ProcessBuilder – bohuss Mar 30 '17 at 09:11
  • If you use the /qc command, you don't need /silent. `bcompare.exe /qc=binary file1.txt file2.txt` will run a binary comparison on two files and return the result as an exit code. Exit codes and command line switches are defined in the **Command Line Reference** topic in Beyond Compare 4's help file. – Chris Kennedy Apr 03 '17 at 18:28

1 Answers1

1

I met my requirement by slightly changing the arguments passed to the Process Builder. Below is the change I made.

ProcessBuilder processBuilder = new ProcessBuilder("C:\\Program Files\\Beyond Compare 4\\BCompare.exe",
        "file1path", "file2path","/fv=Text Compare", "/qc=binary");

This worked for me.

BIndu_Madhav
  • 577
  • 1
  • 8
  • 21