all.
I'm brand new to this Java thing, but since I have a lot of time scripting in UNIX (Linux and AIX), I've been asked to fix a program that opens and saves a list of files in a specific program.
The variables that I'm getting from UNIX are path names to the files. I've replaced the variables with generic names due to their somewhat sensitive nature. Keep in mind that this program will not be portable, it will only be run on this machine.
I need to build a while loop that will get the output from the command " ps -ef | grep programname | grep -v grep | wc -l " and ensure that I have two instances of "programname" before I exit the loop. The line that has "Build while loop is where I want it, the code afterward consists of mouse moves and key presses.
The variable, "countvariable" is only there if I need it for testing the loop, so it may not be necessary
/* */ import java.awt.AWTException;
/* */ import java.awt.Robot;
/* */ import java.io.IOException;
/* */
/* */ public class auto
/* */ {
/* 7 */ static final String pathvariable1 = "pathvariable1";
/* 8 */ static final String pathvariable2 = "pathvariable2";
/* 9 */ static final String pathvariable3 = "pathvariable3";
/* 10 */ static final String countvariable = "countvariable";
/* 11 */ static final String countvariable = System.getenv("countvariable");
/* 12 */ static final String ENVNAME = System.getenv("pathvariable1");
/* 13 */ static final String pathvariable2 = System.getenv("pathvariable2");
/* 14 */ static final String pathvariable3 = System.getenv("pathvariable3");
/* */ public static void main(String[] paramArrayOfString) {
/* */ try {
/* 13 */ String[] arrayOfString = { ENVNAME +"/bin/myprogram","-G","pathvariable2/pathvariable3/scenario.xml" };
/* 14 */ Runtime localRuntime = Runtime.getRuntime();
/* 15 */ Process localProcess = localRuntime.exec(arrayOfString);
/* */ }
/* */ catch (IOException localIOException)
/* */ {
/* 19 */ localIOException.printStackTrace();
/* */ }
/* */ try
/* */ //Build while loop here to wait for 2 program incidents (ps -ef | grep programname...
/* 23 */ Robot localRobot = new Robot();
/* 24 */ localRobot.delay(5000);
/* 25 */ localRobot.keyPress(10);
///More robot stuff goes here....
/* */ }
/* */ catch (AWTException localAWTException) {
/* 60 */ localAWTException.printStackTrace();
/* */ }
/* */ }
/* */ }
/* Location:
* Qualified Name: auto
* JD-Core Version: 0.6.0
*/
grep -C programnameor even further withpidof, if it is available on your platform. On Gnu/Linux, it is.