0

When i run this script manually then Browser chrome open the site in one tab (which is PERFECT exactly how i needed)

But when i run the same script using Java sample code 10 times, it open Browser but 10 times same page 10 TABs.

Q. How can i tell Java code please run it as it was suppose to be running manual execution (so that i have 1 TAB only?) ?

BASH: /var/tmp/runme.sh (ran 1o times and still have always 1 tab as expected)

export DISPLAY=:0.0
ps aux | grep chromium-browser | awk '{ print $2 }' | xargs kill -9;
sleep 8;
chromium-browser --process-per-site --no-discard-tabs --ash-disable-tab-scrubbing -disable-translate "http://www.oracle.com" &

Java: launch 10 times that script

  system("/var/tmp/runme.sh &");

  public static String system(String cmds) {
    String value = "";
    try {
      String cmd[] = { "/bin/sh", "-c", cmds};
      Process p = Runtime.getRuntime().exec(cmd);
      p.waitFor();
      BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
      String line = reader.readLine();
      while (line != null) {
        value += line + "\n\r";
        line = reader.readLine();
      }
    } 
    catch (IOException ioe) {
      ioe.printStackTrace();
    } 
    catch (InterruptedException ie) {
      ie.printStackTrace();
    }
    return value;
  }

2 Answers 2

1

Java is weired sometimes. Its solved.

1( kill chromium browser before killing the java

2( after killing chromium browser then launch the java application

3( now the tab is 1 and browser is 1

BEFORE: (wrong)

export DISPLAY=:0.0
pkill java;
java -cp SystemV.jar Main.Start "boot chromium now with 1 tab and 1 browser" &
ps aux | grep chromium-browser | awk '{ print $2 }' | xargs kill -9;
chromium-browser --process-per-site --no-discard-tabs --ash-disable-tab-scrubbing -disable-translate "http://www.oracle.com" &

AFTER:

export DISPLAY=:0.0
ps aux | grep chromium-browser | awk '{ print $2 }' | xargs kill -9;
chromium-browser --process-per-site --no-discard-tabs --ash-disable-tab-scrubbing -disable-translate "http://www.oracle.com" &
pkill java;
java -cp SystemV.jar Main.Start "boot chromium now with 1 tab and 1 browser" &
echo "it works now"
Sign up to request clarification or add additional context in comments.

2 Comments

Glad that it solved your issue. But what is this line doing? java -cp SystemV.jar Main.Start "boot chromium now with 1 tab and 1 browser" & And then why are you killing java?
Killing java or killing java holding the process which was executed by exec therefore.
0

Fist remove & from this line system("/var/tmp/runme.sh &");

Second, maybe since, you are using this: "/bin/sh", Java is running the script as different shell every time you invoke using Runtime?

and you are executing /var/tmp/runme.sh from the same shell everytime.

Note: /bin/sh is an interpreter and with Java Runtime you are invoking multiple instances of it to execute your script every time.

5 Comments

oh /bin/sh is kind a magic keyword to specify the interpreter syntax you are using to write the script. And obviously to specify where your script interpreter exist.
To check it further, may be you can fire up two terminals and execute /var/tmp/runme.sh.
No No - that's not what I mean. Please see my previous comment.
Hi, I'm there in chat if you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.