# Using Runtime.exec() to execute the graph

**URL:** <https://forum.cloverdx.com/t/using-runtime-exec-to-execute-the-graph/916>\
**Category:** CloverDX Platform\
**Created:** [August 25, 2011, 12:00am UTC](https://forum.cloverdx.com/t/using-runtime-exec-to-execute-the-graph/916 "2011-08-25T00:00:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![angel](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@angel](https://forum.cloverdx.com/u/angel)\
**Post date:** [August 25, 2011, 12:00am UTC](https://forum.cloverdx.com/t/using-runtime-exec-to-execute-the-graph/916/1 "2011-08-25T00:00:00Z")

</div>

I am using Runtime.exec() to execute the graph from Java.Graph runs pretty well and outputs 800000 records and it doesn’t stop either the JVM or the graph but stops writing to the output.  
When I see the log’s the out: and KB never change for the rest of the time.I tried increasing the JVM, log level off,no debug no change.  
I assumed my command or my graph was wrong so tried executing the same graph via command line it executes perfectly and gives me result more than 800000 records.

Below is the sample code.please suggest me what’s wrong with my code or did i miss any arguments?

public String Graph() {  
graph =“java -Djava.io.tmpdir=/opt/tomcat/ -cp com.clover/lib/lib/\* org.jetel.main.runGraph  
-plugins clover/lib/plugins -loglevel OFF -checkconfig -nodebug -config properties/defaultProperties.cfg  
-debugdirectory Debug graph.grf”;

return graph;  
}

public void runGraph() {  
try {  
p = Runtime.getRuntime().exec(Graph());  
readProcess(p,“graph failed”);  
} catch (IOException e) {  
e.printStackTrace();  
}  
}  
public void readProcess(Process p2, String sub) {  
String s=“”,message=“”;  
try{  
stdInput = new BufferedReader(new InputStreamReader(p2.getInputStream()));  
stdErr = new BufferedReader(new InputStreamReader(p2.getErrorStream()));  
int i=0;  
while ((s = stdInput.readLine()) != null) {  
if (s.contains(“ERROR”) && !s.isEmpty()) {

message += s + “\r\n”;  
while ((s = stdInput.readLine()) != null) {  
if (s.contains(“TIMER”) || s.contains(“INFO”) || s.startsWith(“DEBUG”) || s.startsWith(“INFO”))  
break;  
message += s + “\r\n”;  
}  
}  
}  
while((s = stdErr.readLine()) != null){  
message += s + “\r\n”;  
}  
if (message != “”) {  
email.setBody(message);  
email.setSubject(sub);  
email.send();  
System.out.println(sub);  
System.exit(0);  
}  
}catch(IOException e){  
e.printStackTrace();  
}

}

---

<div class="post-metadata">

**Author:** ![avackova](https://avatars.discourse-cdn.com/v4/letter/a/65b543/32.png) [@avackova](https://forum.cloverdx.com/u/avackova)\
**Post date:** [August 26, 2011, 11:48am UTC](https://forum.cloverdx.com/t/using-runtime-exec-to-execute-the-graph/916/2 "2011-08-26T11:48:37Z")

</div>

Hello Angel,  
at least you don’t wait for the process to finish its job (_p2.waitFor()_).  
By the way: why do you execute the graph from java by calling the external system process? You’d rather call our classes, that are designed to execute the graph from java. For more information see [Embedding clover](http://wiki.cloveretl.org/doku.php?id=embedding%5Fclover) and [Tips for Integrating CloverETL to Third Party Applications](http://blog.cloveretl.com/2010/08/06/tips-for-integrating-cloveretl-to-third-party-application/).

---

<div class="post-metadata">

**Author:** ![angel](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@angel](https://forum.cloverdx.com/u/angel)\
**Post date:** [August 26, 2011, 3:35pm UTC](https://forum.cloverdx.com/t/using-runtime-exec-to-execute-the-graph/916/3 "2011-08-26T15:35:40Z")

</div>

Hi Agata,

Thank you for the respone.

But my logic runs perfectly for other Graphs without the waitfor() (lets say around 80million records) except for this graph which uses the Initiate Connection to search the data.

The Graph uses these components  
datareader-\>partition-\>initiate(16 instances)-\>reformat(32)-\>simplegather-\>datawriter

Thanks,  
Angel

---

<div class="post-metadata">

**Author:** ![angel](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@angel](https://forum.cloverdx.com/u/angel)\
**Post date:** [August 26, 2011, 4:21pm UTC](https://forum.cloverdx.com/t/using-runtime-exec-to-execute-the-graph/916/4 "2011-08-26T16:21:04Z")

</div>

Hi,

Sorry new to forums forgot to mention why we haven’t used your classes to execute from java since we didn’t want to perform any sort of maintenance on this java application.Any type of edit to graphs will be done in the workspace and move the graph to our Linux and execute multiple graphs one by one.

Thanks,  
Angel

---

<div class="post-metadata">

**Author:** ![angel](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@angel](https://forum.cloverdx.com/u/angel)\
**Post date:** [August 26, 2011, 9:26pm UTC](https://forum.cloverdx.com/t/using-runtime-exec-to-execute-the-graph/916/5 "2011-08-26T21:26:38Z")

</div>

Hello Agata,

Please ignore the other two messages.I assumed that clover class need maintenance but it seems using the below logic  
I might be able to do the same.But now I got this exception saying  
ERROR [WatchDog] - Node DATA\_READER0 error details:  
java.io.IOException: No space left on device  
at sun.nio.ch.FileDispatcher.write0(Native Method)

I know the cause its cause due to the temp space. But Is there any field to change the temp path like command line below  
java -Djava.io.tmpdir=/opt/tomcat/ that can be added to the logic or do i have to change it in the env variable in linux

//logic  
EngineInitializer.initEngine(“plugins”, “defaultProperties.cfg”, null);  
String graphPath = “Graph.grf”;  
InputStream is = new BufferedInputStream(new FileInputStream(graphPath));

TransformationGraph graph = null;  
GraphRuntimeContext runtimeContext = new GraphRuntimeContext();  
runtimeContext.setDebugDirectory(“Debug”);

graph = TransformationGraphXMLReaderWriter.loadGraph(is,runtimeContext.getAdditionalProperties());  
EngineInitializer.initGraph(graph, runtimeContext);  
Future futureResult = runGraph.executeGraph(graph, runtimeContext);

---

<div class="post-metadata">

**Author:** ![avackova](https://avatars.discourse-cdn.com/v4/letter/a/65b543/32.png) [@avackova](https://forum.cloverdx.com/u/avackova)\
**Post date:** [August 29, 2011, 9:27am UTC](https://forum.cloverdx.com/t/using-runtime-exec-to-execute-the-graph/916/6 "2011-08-29T09:27:15Z")

</div>

Hello,  
unfortunately it is not possible to change CloverETL temp directory. The only way to do this is to run java with the _-Djava.io.tmpdir=/opt/tomcat/_ option.

---

<div class="post-metadata">

**Author:** ![angel](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@angel](https://forum.cloverdx.com/u/angel)\
**Post date:** [August 29, 2011, 4:44pm UTC](https://forum.cloverdx.com/t/using-runtime-exec-to-execute-the-graph/916/7 "2011-08-29T16:44:40Z")

</div>

Hello,

Is there a way to redirect the console output to a file or just set to loglevel to ERROR.

Tried setting it to  
runtimeContext.setloglevel(Level.OFF|LEVEL.ERROR);

It seems no effect and the logging start from the EngineInitializer

Thanks,  
Angel

---

<div class="post-metadata">

**Author:** ![avackova](https://avatars.discourse-cdn.com/v4/letter/a/65b543/32.png) [@avackova](https://forum.cloverdx.com/u/avackova)\
**Post date:** [August 31, 2011, 11:02am UTC](https://forum.cloverdx.com/t/using-runtime-exec-to-execute-the-graph/916/8 "2011-08-31T11:02:33Z")

</div>

Hello Angel,  
CloverETL uses log4j for logging. You can create your configuration file (see [Logging](http://wiki.cloveretl.com/doku.php?id=running#logging)) and use it in your program:

```auto
PropertyConfigurator.configure("<path_to_your_log4j_properties_file>");

```
