• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to run this batch-file (.bat)?  RSS feed

 
Kilia Verdon
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody,

I am not sure if my posting is in the right subforum, but I hope so.

My question:

I wrote a short .bat file to run a task:
C:\SQLTask.bat

"C:\Programme\Microsoft SQL Server\90\Tools\Binn\SQLCMD.Exe" -i "C:\code.sql"
pause


This bat-file runs an sql file without opening microsoft sql management studio. If I run the file a dos-window is beeing opened and displays an sql report (how many lines have been affected and so on).

Now I would like to run this bat-file out of a java program. I used:
Runtime.getRuntime().exec("C:\\SQLTask.bat");

Unfortunately no DOS Window is beeing displayed (and I need the report of the sql server).

How do I have to change my code in order to run the bat-file out of my java tool and to open a dos window, which displays the report ?

I tried with Start "C:\Programme.... -> but I dont know how to set the quotes. it does not work

It would be very nice if someone could help me.

Thanks a lot
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the API doc for Process and look at some examples.
There are methods to read the output from the program that is being executed.
 
Rob Spoor
Sheriff
Posts: 21131
87
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You won't find the answer in Process.

The thing is, the command window is triggered by the OS when you run the batch file directly. When you execute it through Java, it won't trigger the command window.

Fortunately, you can call it yourself. Change your command to "CMD.exe /C C:\\SQLTask.bat" - this won't call the batch script but calls a command window in which the script will be run. Check out "cmd /?" for more info.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to see the output, it's better to use cmd /K. This will leave the command window open afterwards. cmd /C runs the command and then closes the window.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!