Showing posts with label Batch file. Show all posts
Showing posts with label Batch file. Show all posts

Tuesday, June 12, 2012

Is it possible to run a .bat file in Linux?

No

You will have to change the file to the Linux format, .sh file and then execute it.


Example:

I have a TESTTool folder which contains 2 folders:
1. bin folder with a Tool.jar file &
2. lib folder with Communication.jar file in it


start.bat file looks like this:

cd bin
java -classpath ..\lib\*;Tool.jar testtool.UIFrame


..\lib\* command selects all files in the folder lib.


The folder was added in Ubuntu PC and then provided permission to it.
And the file start.bat was Saved as start.sh file.

But while executing the application, it throws error :

Could not find the Communication class..

Issue 1:
Linux will not select the files in the folder using the command,
..\lib\*;

You have to specify the jar file in the lib folder.

Issue 2
After saving a .bat file to .sh file,
You have to convert the .sh file into linux format using the command
dos2unix start.sh


The start.sh file will look like:

cd bin
java -classpath ../lib/Communication.jar:Tool.jar testtool.UIFrame

Tuesday, November 2, 2010

Execute SQL file using a batch file

My task was to run a batch file for executing a SQLfile (CreateTables.sql) containing queries to create database, some tables and their fields.


I’ve installed MYSQL Server in my PC.


Initially check whether MYSQL environment variables have been set. If not, set the path using,
Right click My Computer --> Properties --> Advanced --> Environment Variables --> System Variables --> Click on the PATH variable --> Click on Edit --> At the end of Variable Value, add the following
C:\Program Files\MySQL\MySQL Server 5.0\bin;
(The bin path of your MYSQL Server)



Initially create a batch file using the following steps.


Step 1: Open a notepad window.
Step 2: Type the following commands.


@echo off
echo please wait........


mysql --user=root --password=admin<CreateTables.sql



mysql --user=YourMYSQLUsername --password= YourMYSQLPassword <Your SQL filename
(In case your SQL file and batch files are in different folder, you have to specify the full path of SQL file.
Eg:- mysql --user=YourMYSQLUsername --password= YourMYSQLPassword <D:\Folder1\Your SQL filename )



Step 3: Save the filename as “filename.bat” (Include the filename within double quotes)
Step 4: Double click the batch file.



While executing the batch file, the following output will be displayed. 








Note: If you are using Windows XP, make sure that the batch file is not in your desktop.