Running Batch files in java

Running Batch files in java

View Answers

March 13, 2009 at 7:08 AM

Hi Friend,

Here we are sending you some sample program code for running batch (.bat) file in Java. We have used "exec()" command for running the batch file. Suppose we have created a batch file "notepd.bat" which calls the notepad and this is responsible for opening a notepad.

notepd.bat
==========

echo "This would open notepad"
CALL notepad

Our java class is "CallBatchFile.java" who runs the bat file.
CallBatchFile.java
==================
import java.io.*;
class CallBatchFile{
public static void main(String args[]){
try
{
System.out.println("Start Running the batch file");
Runtime.getRuntime().exec("notepd.bat");
System.out.println("Completed");
}
catch (Exception e)
{
e.printStackTrace();
}
}
}

Output :
C:\>javac CallBatchFile.java

C:\>java CallBatchFile
Start Running the batch file
Completed
and one notepad window will be open.

Thanks & Regards
RoseIndia Team









Related Tutorials/Questions & Answers:
Running Batch files in java - Java Beginners
Running Batch files in java  Hi, I am writing a program which... are sending you some sample program code for running batch (.bat) file in Java. We have... and every line from the batch file and execute it line by line in java. Is anyone
i want to copy files from one machine to other using java and the code will be running on third machine
i want to copy files from one machine to other using java and the code will be running on third machine  i want to copy some files from one machine say 'A' to some other machine say 'B' by using the java program running on third
Advertisements
Running a stand alone application using batch file in windows
Running a stand alone application using batch file in windows  I have... application. All the .class files are available inside a package called as com.tbss. I have included all the jar files inside the present working directory.I have used
Running Java Applications as software
Running Java Applications as software   Please tell me what to do if you want your java application to run like a real software,eg a java GUI application that connects to the database(Mysql)running on the computer like any other
running java with classpath in cygwin
running java with classpath in cygwin  The following command works in cmd.exe but failts in cygwin shell. java -cp .;oracle.jar;mysql.jar Executecmd query value; how should i alter the command to run in the bash shell?thanks
Running core java program
Running core java program  I am jayesh raval. I am going to make simplae program and at the time of runnint that program I found class not found exception. I have clear source of that program and that is right in the syntax. so
process of compiling and running java program
process of compiling and running java program  Explain the process of compiling and running java program. Also Explain type casting
Java Not running - Java Beginners
Java Not running  Hi, I tried to create a grade(type array) and final_grade (type of String) program using getter/setter but not want a public setter method for final_grade; Here is my program that calcuate the average of all
Running Java Applications as a Windows Service
Running Java Applications as a Windows Service  sample code for "Run a Java application as a Windows Service
Building and Running Java 8 Support
Building and Running Java 8 Support  As you know Java 8 is already released and available for download. Now I am developer of Java based projects. So... and run Java 8 application in Eclipse? Thanks   Hi, don't worry
Server running Button - Java Beginners
Server running Button  Hi there, I have a created a GUI using NetBeans IDE 6.1. The aim of this interface is to display the messages that have been recived by the server , when the client is connected , in the textArea
Java Compilation and running error - RMI
Java Compilation and running error   The following set of programs runs with the lower versions of Java 6 update 13, but not with JAVA 6 update 13... some problem and gives following on compilation"java uses unchecked or unsafe
java web application without running tomcat
java web application without running tomcat  I did a project by using jsp,html,javascript,css,tomcat,editplus and MSAccess as backend..i created set... is there any way to run the web application(only in single system)without running
regarding java files genarated by jsp
regarding java files genarated by jsp  Hi,... I'm running a project...: 233 in the generated java file Syntax error, insert "}" to complete Block" Where to find the genarated java file??? Thank u in advance
Trouble in running Dos Command from Java Servlet
Trouble in running Dos Command from Java Servlet  Hello All, I have to run following command from Java. The command is : vscanwin32 /S C:\Test > C:Scan_Result.txt vscanwin32 is resided at location: C:\Program Files\Trend
java files - Java Beginners
java files  Hi! How to create files (not temporary) when i got exception in my java program. I want to write the complete exception in file...://www.roseindia.net/java/example/java/io/ Thanks
Java files - Java Beginners
Java files  i want to get an example on how to develop a Java OO application which reads, analyses, sorts, and displays student project marks.... The input files are structured as follows: ˆ one student record per line ?
java and files - Java Beginners
java and files  hi this is varun working for a software company. i have one doubt that is i have written a program for accessing the xml file from java code,its get executed for that i have used XML Prser. but now
Reading files in Java
suggest for Reading files in Java? Thanks...Reading files in Java  I have to make a program in my project... file in Java. What is the best way to read the file in Java as its big file
Copy Files - Java Beginners
Copy Files  I saw the post on copying multiple files (http://www.roseindia.net/java/example/java/io/CopyMultipleFiles.shtml) and I have something... a list of JPEG files that my boss gave me, and I was planning on putting them
files - Java Beginners
files  Why do we require files to store data?  Hi friend, files to store data, easy to find and access them. Thanks
configuration files - Java Beginners
configuration files  i have to use configuration file in my program "listing of number of files and their modified time of directory",but problem is that directory name should be provided through configuratin file not input
listing files - Java Beginners
listing files  how to list the files and number of files only...]); System.exit(0); default : System.out.println("Multiple files...]); System.exit(0); default : System.out.println("Multiple files are not allow
Batch file for java application
Batch file for java application  please tell me how to create the batch file for java application(using swings).the application is created with netbeans
error while running the applet - Java Beginners
error while running the applet  import java.applet.Applet; import...); ++num; } } } } i have problem while running the code , error... is correct but u have problem in running the program. You follow the following steps
files
.   Please visit the following link: http://www.roseindia.net/tutorial/java/core/files/storeobjectsinFile.html
files
files  write a java program to calculate the time taken to read a given number of files. file names should be given at command line.   Hello Friend, Try the following code:ADS_TO_REPLACE_1 import java.io.*; import
executing a batch file which depends on jar files from a system tray but console should not display.
executing a batch file which depends on jar files from a system tray but console should not display.  Hi all, I got following requirement, I have to run a batch file which is depending on some jar files and it displays a frame
Compiling and Running Java program from command line
Compiling and Running Java program from command line - Video tutorial... of compiling and running java program from command line. We have also video... to explain you the process of compiling and running the Java program from command
Java Batch Execution
Java Batch Execution  In a statement, I am executing a batch. What... contains the affected row count in the corresponding index of the SQL. batch... count and error information. The batch may be executed during autocommit
Running JUnit
Running JUnit  Hi sir How can we run JUnit or Run test case Using JUnit using command prompt or CMD? Is there any alternate way of running test cases?   ou can run JUnit test case by running following command on CMD
using java files - Java Beginners
using java files  how i use files in java to store as eg. (information about movies as its name) & when user ask about some movie the movie will come with a picture associated with it plz write me a couple of line codes
How to Communicate with the operating system embedded on processor running on hardware machine in java
How to Communicate with the operating system embedded on processor running... system embedded on processor running on hardware machine .Now as per my need i have to communicate with the opearating system using java tools. Will you plz
Java Concatenate files
Java Concatenate files In this section, you will learn how to concatenate files in java. Concatenating a file, or a series of files, to a single file... have listed the files using listFile() from a particular directory
Filter Files in Java
Filter Files in Java       Introduction The Filter File Java example code provides the following functionalities: Filtering the files depending on the file
Running JUnit
Running JUnit  Hi sir How can we run JUnit or Run test case Using JUnit using command prompt or CMD? Is there any alternate way of running test cases?   Hi friendADS_TO_REPLACE_1 You can run JUnit test case by running
Reading and Writing files - Java Beginners
Reading and Writing files  Hello, please help me to Develop a simple Java application that, when run, Welcomes the users and tells them the name... to investigate writing to files a little (can be also done using Properties
Reading Files and Print - Java Beginners
Reading Files and Print  Hey Guys, I'm a beginner to java and I wanna write this program. I wanna create files including information.... There are almost 30 files. When I want to find students whose school is "School
how to backup files and folder with Java
how to backup files and folder with Java  Does anyone know to create a backup with java?. backup files and folders from my computer to an external drive.   hi friend, Try the following code may, this will be helpful
list files only - Java Beginners
list files only  i have to list only files and number of files in a directory? i use list() method but it returns both files and directories in parent directory.are there any specific methods that show only files? are file
How to Get currently running processes in a tabular form in java
How to Get currently running processes in a tabular form in java  I need to create a frame that shows all the current running processes in the system in a tabular form. i used Process proc = runtime.exec(cmds); but it only gives
java-select dynamic files. - Java Beginners
java-select dynamic files.  My java program is processed files. Now i... in run time. How to insert new files in run time. I need to take system file.(file -> open ) I want to this windows in my java project.   Hi
why it is very slow when I am using the backend as microsoft access file for running the java webapplication - SQL
why it is very slow when I am using the backend as microsoft access file for running the java webapplication  I am using the backend as microsoft access file for running the java webapplication.it is very slow when twoor mor
File handling in Java, Java Files
Java File Handling Tutorials In this tutorial we are providing many different examples of handling file from Java program. The Java File Handling Tutorials will help you learning the file handling concepts in Java. The Java
How do I decompile Java class files?
How do I decompile Java class files?  How do I decompile Java class files
How to avoid Java Code in JSP-Files?
How to avoid Java Code in JSP-Files?  How to avoid Java Code in JSP-Files
Java: Searching a string from doc files
Java: Searching a string from doc files   I want to search a string from DOC, DOCX files in java. Can anyone please help me
Java programming help with files - Java Beginners
Java programming help with files  I want a code or the following... then forms two files to store the data; an american employees file and a non-american employees file. The program finally opens the files for output and prints
Append winword files in java - Java Beginners
Append winword files in java  HI, Im trying to merge 2 winword documents containing text, tables and pictures, resulting doc file should have the same formatting as in original docs. My platform is windows XP and office
setting path problem for org.jfree files - Java Beginners
\Java\j2sdk1.5.0\bin;C:\Program Files\Java\j2sdk1.5.0\lib\jcommon-1.0.8.jar;C:\Program Files\Java\j2sdk1.5.0\lib\jfreechart-1.0.4-demo.jar;. and when iam... have downloaded two files jar files and placed them in lib folder to work

Ads