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
JM

Recommended Answers

All 4 Replies

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 

C:\WINDOWS\system32>mspaint

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?

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;
		//Utils.log(batchFilePath);
		p = r.exec(new String[]{"cmd","/C",batchFilePath});
		BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
		String line = null;
		while((line=input.readLine()) != null) {
			System.out.println(line);
		}
		}

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.