i do have a class CheckPrograminstallation(which is part of a eclipse plugin), with a method check, which checks whether a program is installed. It return true when installed and false otherwise.
public class CheckPrograminstallation{
public static boolean check(String programname, String OsName)
throws Exception {
// Get installation path of programname
String foundpath = "";
String dirName = "";
String line;
String programpath = null;
Process process = null;
boolean IsInstalled = false;
if (OsName.equals("Windows")) {
try {
// get Windows Directory first
process = Runtime.getRuntime().exec("cmd /c echo %windir%");
BufferedReader reader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
// read from stream
if ((line = reader.readLine()) != null) {
foundpath = line.toString();
// cut off "\Windows" from the found path
int last = foundpath.lastIndexOf("\\");
dirName = foundpath.subSequence(0, last).toString();
process = null;
// get program installation path
process = Runtime.getRuntime().exec(
"cmd /c where /R " + dirName + " " + programname);
reader = new BufferedReader(new InputStreamReader(
process.getInputStream()));
if ((line = reader.readLine()) != null) {
programpath = line.toString();
System.out.println(programpath);
IsInstalled = true;
}
}
} catch (Exception e) {
DO SOMETHING);
}
}
When i call the method from a test class, it works. But when i call the same method while running the Plugin:
...boolean isInstalledPscp;
boolean IsWindows;
...
if (IsWindows == true) {
// for Windows: check if pscp is installed
isInstalledPscp = CheckIfInstalled.check("pscp", "Windows");
if (isInstalledPscp == false) {
do something }
}
...it always returns false. How can that be?
This has been driving me crazy for a whole day. Using .equals for String comparison, and still getting false as result. So this is not a string comparison problem IMHO.