I'm very nubby at Java, so please excuse me if is a dummy question. I have the following piece of code, and the execution flow is different from my intention:
channel = session.openChannel("shell");
OutputStream ops = channel.getOutputStream();
PrintStream ps = new PrintStream(ops, true);
channel.connect();
String sudo = "sudo su - user";
String copy = "copy from a to b;
String cd = "cd a directory";
String runload = "run a scrip in unix;
String cd1 = "cd a directoryu";
String executeload = "run a scrip in unix";
ps.println(sudo);
ps.println(copy);
ps.println(cd);
ps.println(runload);
ps.println(cd1 );
if (db.runload().contains("SUCCESS")) {
ps.println(executeload);
//execute this only if runload was success
} else {
System.exit(1);
}
The point is that "if block" is executed before previous lines. runload
is script which load information in a table and is a precondition for executeload
. In this case executeload
will throw java.lang.NullPointerException
.
My question is: it Is a way to control the flow in this piece of code? Every previous line is a precondition to the next one. My intention is to execute the next line when the current is finally executed.