| Author |
How to run this batch-file (.bat)?
|
Kilia Verdon
Greenhorn
Joined: Jan 20, 2008
Posts: 13
|
|
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
Ranch Hand
Joined: Aug 10, 2005
Posts: 681
|
|
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
Joined: Oct 27, 2005
Posts: 19216
|
|
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.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Joanne Neal
Rancher
Joined: Aug 05, 2005
Posts: 3011
|
|
|
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.
|
Joanne
|
 |
 |
|
|
subject: How to run this batch-file (.bat)?
|
|
|