0

This is a common problem from what I see, but I tried to incorporate some of the suggestions provided. None worked for me. Am I making a mistake here? This is what I am trying to do.

String[] comd1 = { "/bin/sh", "-c", "sesearch", "--allow -s "+tokens[1]," -t     "+tokens[2].split(":")[0]," -c "+tokens[2].split(":")[1]," -p "+tokens[3].replace(";","")," sepolicy" };

Process pp = Runtime.getRuntime().exec(comd1);
stdInput = new BufferedReader(new InputStreamReader(pp.getInputStream()));
                        String temp, status = null;
                        boolean flag = false;

                        while ((temp = stdInput.readLine()) != null) 
                        {
                            if(temp.contains("Found ") || temp.equals("") || temp.contains("Usage"))
                            {
                            }
                            else
                                flag = true;
                        }  
                        if(flag) status="Yes"; else status="No";

The flag which is initially set to false, is always false. It never sets to true. I have tried nearly every combination of the comd1 string array.

Please help.

  • Try running the command from command line. What is the output? – Sotirios Delimanolis Sep 20 '13 at 00:01
  • 1
    Each element in you `comd` array MUST be a separate parameter. Each element is interpreted by the program you are calling as a indiviual parameter (think of it like `main(String[] args)`, each element will be a element in the `args` list). Try using something more like `{"/bin/sh", "-c", "sesearch", "--allow", "-s", tokens[1], "-t", tokens[2].split(":")[0], "-c", tokens[2].split(":")[1], "-p", tokens[3].replace(";",""), "sepolicy"}`. I don't know if this will fix the problem, but it will get you a step closer... – MadProgrammer Sep 20 '13 at 00:04
  • Also, use `ProcessBuilder` and redirect the error output to the std output... – MadProgrammer Sep 20 '13 at 00:04
  • Sotirios: The command line version gives me the correct output. Its just that its not working when I try from within my java code. – user2797397 Sep 20 '13 at 00:44
  • MadProgrammer: I tried this too. No luck. The return value on the screen will be null. – user2797397 Sep 20 '13 at 00:45

0 Answers0