Running batch script using JAVA and storing output in a log file.
Batch script to be run will take input parameters / arguments.The below simple Java code will help to run a batch file (bat script) and store the output of batch run in to a file. The batch script to be run from the java takes few parameters as inputs.
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.InetAddress;
public class ApplicabilityCheck {
public static void main(String[] args) {
try {
System.out.println("ESS BVT");
String cfgprefix = "server1";
InetAddress hostname = InetAddress.getLocalHost();
String host = hostname.getCanonicalHostName();
String httpsPort = "16311";
String truststorepassword = "krishna";
String basicauthuser = "krishna";
String basicauthpassword = "krishna";
String essCleintPath = "C:\\Krish\\My Docs\\Foundation services install\\ESS - 15183\\ESSAuthnClientApp\\MyApp\\bin";
String essOutputDir = "C:\\Krish\\My Docs\\Foundation services install\\ESS - 15183\\ESSAuthnClientApp";
String passString = "succeeded";
File tokenOutFile = new File("ESS_Token_Out");
File essOutputFile = new File(essOutputDir + "\\ESS_OUTPUT.log");
File iosdpTrustStoreFile = new File(essCleintPath + "\\16311.jks");
File runExampleFile = new File(essCleintPath+ "\\runExampleApp.bat");
if (iosdpTrustStoreFile.exists() && runExampleFile.exists()) {
System.out.println("File:- "
+ iosdpTrustStoreFile.getAbsolutePath() + " Exists");
String setupExampleString = "setupExampleApp.bat -cfgprefix "
+ cfgprefix + " -host " + host + " -port " + httpsPort
+ " -protocol https -truststorelocation \""
+ iosdpTrustStoreFile.getAbsolutePath()
+ "\" -truststorepassword " + truststorepassword
+ " -basicauthuser " + basicauthuser
+ " -basicauthpassword " + basicauthpassword;
System.out.println(setupExampleString);
String runExampleAppString = "\""
+ runExampleFile.getAbsolutePath() + "\" " + cfgprefix
+ " -tokenOutFile " + tokenOutFile.getName() + " -uname "
+ basicauthuser + " -pword " + basicauthpassword;
System.out.println(runExampleAppString);
/* Now running the Run Example */
Runtime runtime = Runtime.getRuntime();
Process p = runtime.exec(runExampleAppString, null, new File(essCleintPath));
String line;
BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedWriter w = new BufferedWriter(new FileWriter(essOutputFile));
while ((line = r.readLine()) != null) {
if(line.contains(passString)) System.out.println("ESS installed");
w.write(line);
}
r.close();
w.close();
} else
System.out.println("Trust Store JKS file is not available");
} catch (Exception e) {
System.out.println(e);
}
}
}
References:
[1]
1 comments to "Running a batch script from Java(Arguments for Bat file) and output of run in a file"
Post a Comment
Whoever writes Inappropriate/Vulgar comments to context, generally want to be anonymous …So I hope U r not the one like that?
For lazy logs, u can at least use Name/URL option which doesn’t even require any sign-in, The good thing is that it can accept your lovely nick name also and the URL is not mandatory too.
Thanks for your patience
~Krishna(I love "Transparency")
Popular Posts
-
The best solution to know about these init levels is to understand the " man init " command output on Unix. There are basically 8...
-
How to Unlock BSNL 3G data card to use it with Airtel and Vodafone Model no : LW272 ? How to unlock BSNL 3G data card( Model no : LW272 )us...
-
How to transfer bike registration from one State to other (Karnataka to Andhra)?? Most of us having two wheelers purchased and registered in...
-
ఓం శ్రీ స్వామియే శరణం ఆయ్యప్ప!! Related posts : Trip to Sabarimala - Part 1 Trip to Sabarimala - Part 2 Ayappa Deeksha required things...
-
Following are some of interesting blogs I found till now ...please comment to add your blog here. Blogs in English : http://nitawriter.word...
Popular posts
- Airtel and vodafone GPRS settings for pocket PC phones
- Andhra 2 America
- Ayyappa Deeksha required things
- Blogs I watch !
- Captions for your bike
- DB2 FAQs
- Deepavali Vs The Goddes of sleep
- ETV - Dhee D2 D3
- Evolution of smoking in India Women
- How to make credit card payments?
- init 0, init 1, init 2 ..
- Java-J2EE interview preparation
- mCheck Application jar or jad download
- My SQL FAQs
- My Travelogues
- Old is blod - New is italic
- Online pay methids for credit cards
- Oracle FAQs
- Pilgrimages
- Smoking in Indian Women
- Technology Vs Humans
- Twitter feeds for all Telugu stars on single page.
- Unix best practices
- Unix FAQs
Anonymous says:
For hottest information you have to visit web and on world-wide-web I found this
web site as a finest web site for latest updates.
Take a look at my web site Deux Lux handbag