Results 1 to 11 of 11
  1. #1
    jmHoekst is offline Member
    Join Date
    Jun 2008
    Posts
    14
    Rep Power
    0

    Default Determining the readiness of another program

    Greetings,

    I am looking for ideas on how to be able to tell if a program is fully loaded and ready for input. I am using

    Runtime.getRuntime().exec("programName");

    to start my program and the program can take between 10 seconds and 10 minutes to load. After the program is loaded, I have several automation steps being done, so they can't be started until the program has loaded.

    Any ideas on how I can interact with my Windows XP os to determine if the program is ready for input? Whether it is using Java, or some other language/technique?

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Loading a program means, initialize all the process to make required functionality. So you have a sequence of processes. If you know what is the last process to load, until it's successful disable the user interactions with the application. Just an idea this is, on what I thought the easy way.

  3. #3
    jmHoekst is offline Member
    Join Date
    Jun 2008
    Posts
    14
    Rep Power
    0

    Default

    Is there some kind of a way to perhaps get the %cpu usage from the system? That would be a perfect indicator of the system readiness. Maybe through JNI? Anybody have any ideas?

  4. #4
    jmHoekst is offline Member
    Join Date
    Jun 2008
    Posts
    14
    Rep Power
    0

    Default

    Eranga,

    What you are saying sounds very good, but what tools are necessary to determine if the last process is successful? Either way, I think I will have to use a JNI or interface with C or VB to determine CPU %? Unless somebody has an alternative solution or suggestion...?

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Not a bad idea though. But how we define the CPU usage level. I mean how can we find that looking the usage a specific process is completed. Just look at the CPU usage without doing any on your system. Still you can see that usage level change from 0% to up, and upper level has no pre-defined level.

    If you want to find the CPU usage, best solution is C/C++ interface, I think.

  6. #6
    jmHoekst is offline Member
    Join Date
    Jun 2008
    Posts
    14
    Rep Power
    0

    Default

    Thanks for the advice Eranga, I have since made a small VBScript that will get the current CPU% on my system. Now, how would I use my Java program to call that script, and how would I get the value from the VBScript to my Java program?

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    I've never do this. I hope using a runtime process we can run a VBScript. But the question is how to handle the output of the script. This is the way to run a script.

    Java Code:
    Runtime.getRuntime().exec("wscript.exe path_to_your_script");

  8. #8
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    Last monthes we are working for a driver center in Java code for Linux Sam,and to have an output of the command we do the following:

    Java Code:
    import java.util.*;
    import java.io.*;
    import javax.swing.*;
    public class Shell {
    	private static String command = "ls -Als";
    	private static String command2 = "cat /etc/profile";
    	private String string="";
    	public static void main(String[] args) throws java.io.IOException {
    		JFrame frame=new JFrame("Output");
    		JTextArea textArea=new JTextArea();
    		textArea.setEditable(false);
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		frame.pack();
    		frame.getContentPane().add(textArea);
    		frame.setSize(500,800);
    		frame.setVisible(true);
    		try {
    	        
    	        Process child = Runtime.getRuntime().exec(command);
    	    
    	        // Get the input stream and read from it
    	        InputStream in = child.getInputStream();
    	        int c;
    	        while ((c = in.read()) != -1) {
    	            textArea.append(String.valueOf((char)c));
    	        }
    	        in.close();
    	    } catch (IOException e) {
    	    }
    try {
    	        
    	        Process child = Runtime.getRuntime().exec(command2);
    	    
    	        // Get the input stream and read from it
    	        InputStream in = child.getInputStream();
    	        int c;
    	        while ((c = in.read()) != -1) {
    	            textArea.append(String.valueOf((char)c));
    	        }
    	        in.close();
    	    } catch (IOException e) {
    	    }
    		
    
    }
    }
    You can do the same for windows,you can also access the PCB table to know if the process is launched and then to go with the next command.

    I know the shell command to know if the process launched in Linux,but there is also a dos command for that,search for it buddy.
    Last edited by serjant; 06-19-2008 at 08:26 AM.

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    What this replay mean. Seems to me there is no any connection with the original thread. I see that you have post the same post in several threads.

  10. #10
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    yes the code is the same,but read the post up to the end.

  11. #11
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Executing a program within a program
    By gibsonrocker800 in forum New To Java
    Replies: 5
    Last Post: 05-12-2008, 08:24 AM
  2. Replies: 0
    Last Post: 04-04-2008, 02:40 PM
  3. Determining Midi Length
    By Usagi in forum New To Java
    Replies: 0
    Last Post: 12-08-2007, 11:45 PM
  4. Replies: 0
    Last Post: 10-04-2007, 09:33 PM
  5. I need help with this program
    By Daniel in forum Advanced Java
    Replies: 2
    Last Post: 07-04-2007, 05:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •