Results 1 to 4 of 4
  1. #1
    masoumeh is offline Member
    Join Date
    Jun 2013
    Rep Power

    Default Problem with Runtime.getRuntime.exe()

    Hi every body,

    I am trying to execute this commad (/usr/bin/rrdtool lastupdate rrdFile.rrd) in java by Runtime.getRuntime.exe().
    executing this command in a linux shell by RRDTool installed, will read data stored in rrdFile.rrd and prints some numbers as status of my system as return value. but when I execute this command by java, it returns null!
    here is some part of my code:

    String rrdPath = "/var/lib/cacti/rra/localhost_mem_swap_9.rrd";
    String rrdCmd = "/usr/bin/rrdtool lastupdate " + rrdPath;
    String temp = null;
    String cmdStResult = null;
    Process p = null;

    try {
    p = Runtime.getRuntime().exec(rrdCmd);
    int exitVal = p.waitFor();
    System.out.println("exitVal of rrdLastUpdate is : " + exitVal);

    } catch (Exception e) {

    System.out.println("Problem in exec()");

    }//end of try-catch

    try {

    InputStreamReader inStreamReader = new InputStreamReader(p.getInputStream());
    BufferedReader stdInput = new BufferedReader(inStreamReader);

    while ((s = stdInput.readLine()) != null) {
    }//end of while

    } catch (Exception ex) {
    }//end of try-catch

    I think maybe the problem is reading rrfFile and it needs FileInputStream, isn't it?
    help me, plz :)
    any guidance would be appreciated
    thanks a lot.

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Rep Power

    Default Re: Problem with Runtime.getRuntime.exe()

    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    masoumeh is offline Member
    Join Date
    Jun 2013
    Rep Power

    Default Re: Problem with Runtime.getRuntime.exe()

    Quote Originally Posted by PhHein View Post
    yes. because nobody answered me there, I asked my question here. I should solve this problem earlier.

  4. #4
    masoumeh is offline Member
    Join Date
    Jun 2013
    Rep Power

    Default Re: Problem with Runtime.getRuntime.exe()


    I could get over the previous problem somehow, as example for rrdtool fetch:
    String rrdCmd = "rrdtool fetch localhost_mem_swap_9.rrd AVERAGE -s -10min -e now";

    Java Code:
    String rrdCF = "AVERAGE";
            String rrdtm1 = "-s -10min";
    	String rrdtm2 = "-e now";
    	ProcessBuilder pb = new ProcessBuilder("/usr/bin/rrdtool", "fetch", rrdPath, rrdCF, rrdtm1, rrdtm2);

    but the remainder is how to adjust parameters of "rrdtool graph" function to be executed.
    I want to execute this command by the process but it does not execute!

    Java Code:
    String myCmd = null;
    myCmd = "/usr/bin/rrdtool graph myOutputGraph.png --start -10min --end now DEF:a=\"/var/lib/cacti/rra/localhost_
                    mem_buffers_8.rrd":mem_buffers:AVERAGE LINE2:a#FF4105FF";
    the code and its errors are as below (fortunately No exceptin)

    Java Code:
    	String outPath = null; 
    	String opt1 = null , opt2 = null;
    	String s = null;
    	outPath = "/home/mas.png";
    	String rrdtm1 = "-s 1372500300";
    	String rrdtm2 = "-e 1372504500";
    	String rrdDef = "DEF:";
    	String rrdVar1 = "a=\"";
    	opt2 = "\":mem_buffers:";
            String rrdCf = "AVERAGE";
    	String rrdColor = "LINE2:a#FF4105FF";
            ProcessBuilder pb = new ProcessBuilder("/usr/bin/rrdtool", "graph", outPath, rrdtm1, rrdtm2, rrdDef + rrdVar1, 
                                                                        rrdPath, opt2, rrdCf, rrdColor);

    ERROR: Problems reading database name

    I want to know how to arrange parameters of these command for ProcessBuilder.
    any help would be appreciated :)
    thanks a lot :)

Similar Threads

  1. Is there an alternative to Runtime.getRuntime().exec()
    By md_suzon in forum Advanced Java
    Replies: 5
    Last Post: 04-24-2013, 02:17 PM
  2. Why can I use Runtime.getRuntime() in Eclipse
    By ccie007 in forum New To Java
    Replies: 5
    Last Post: 10-18-2010, 06:48 PM
  3. problem with Runtime.getRuntime().exec when running java in .bat
    By Shayko in forum Threads and Synchronization
    Replies: 2
    Last Post: 01-27-2010, 07:46 PM
  4. help with Runtime.getRuntime().exec
    By collin389 in forum AWT / Swing
    Replies: 3
    Last Post: 11-09-2009, 04:22 AM
  5. Problem with Runtime.getRuntime().exec with Linux Commands
    By swapnilnawale in forum Threads and Synchronization
    Replies: 1
    Last Post: 09-23-2009, 10:23 PM

Posting Permissions

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