Search code examples
javacmdrrd

How do i run a Linux terminal cmd from a java program


I am trying to call my rrdtool cmd from a java class, not sure how to go about it.

I have tested my RRDTool cmd from my terminal and it is successful, see below.

rrdtool update mydb.rrd 1385056701:6:5

How do i execute this cmd from a java class?


Solution

  • You can use the below command format to run your Linux command.

    Runtime r = Runtime.getRuntime();
    Process p = r.exec(yourcmd);
    

    Please go through Running unix command from Java and Unable to run Unix command in Java-Stackoverflow

    Hope you get your answers here.