I was working on a client program for Websphere where I need to change WebSphere configuration with an executable jar file that will get input from user and change configuration. As WebSphere uses Jython commands in Windows environment so in this example I am calling bat file from java code that will internally call jython file and pass parameters to set WebSphere configurations.
- package com.bat;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- public class WindowsScript {
- /**
- * @param args
- * @throws IOException
- */
- public static void main(String[] args) throws IOException {
- Runtime rt = Runtime.getRuntime();
- Process process = rt.exec(new String[]{"cmd.exe", "/c", "D:\\test.bat c: \"C:/Program Files/IBM/SDP/runtimes/base_v7/profiles/AppSrv01Secure/bin\" server1 \"a1.rootdir\""});
- InputStream inputStream = process.getInputStream();
- BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
- String line;
- while ((line = bufferedReader.readLine()) != null) {
- if(line.contains("value="))
- System.out.println(line);
- }
- System.out.println("end------");
- }
- }
You can get these parameters in batch file as
- @ECHO OFF
- %1
- cd %2
- jythonCode.py %3 %4 %5
and pass required parameters to jython file so that jython code can perform its operation