Hello Everyone,

I created a java code that runs batch files. Then, I deployed the java classes in apache-tomcat-5.5.26. The code worked when I ran the tomcat manually but when I ran the tomcat as a windows service, it did not work. I checked the tomcat log files but apparently the batch files are not code where I generated some log files.

Can you please give some thoughts regarding this?

Thanks in advance

7 Years
Discussion Span
Last Post by ~s.o.s~

Hello Everyone,

I created a Java Class that runs a batch file. What the batch file does is it will run an .EXE (ex. MSPAINT) file. Then I scheduled the run of the Java Class using Quartz Scheduler and deployed it to Tomcat. When I ran the tomcat manually, it worked but when I ran the tomcat as a windows service, it read the batch file but it did not open the .EXE file. I checked the tomcat log file and I saw the EXE file.

Job Name:TEST 
Started Thu Jan 13 17:42:00 GMT-08:00 2011 


Can you please give me some suggestions or ideas regarding this.

Thanks in advance


What code are you using to "spawn" the batch file in Java?

Thanks for the reply. Please see the code below:

public void run(String batchFilePath,String[] params) throws Exception{
		Runtime r = Runtime.getRuntime();
		Process p = null;
	         String parameters = "";
		for (int i=0;i<params.length;i++){
			parameters += params[i] + " ";
		batchFilePath = batchFilePath + " " + parameters;
		p = r.exec(new String[]{"cmd","/C",batchFilePath});
		BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
		String line = null;
		while((line=input.readLine()) != null) {

Edited by jamojo: n/a


Showing the values of "batchFilePath" and "params" when this code execute would help. Anyways, I personally don't like the "parameter" concatenation part of the code since white-spaces or special characters in parameters might mess things up. Why not just pass the batchFilePath and parameters as it? For array concatenation, read this.

Also, is this "batchFilePath" just the file name? Or is it the complete path?

Edited by ~s.o.s~: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.