aspose file tools*
The moose likes Java in General and the fly likes can't start startup.bat from my application ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "can Watch "can New topic
Author

can't start startup.bat from my application ?

naved momin
Ranch Hand

Joined: Jul 03, 2011
Posts: 692

i was trying to execute tomcat's startup.bat file through my application
but when i use this
it throws an exception saying file not found , i had triple checked that everything is correct and file is present there because exception is IOException "File not found"

then i tried the same thing use Desktop class here the command prompt screen just splashes but nothing happens
the same script runs fine when i start it manually by double click
can you explain me whats wrong here ?

The Only way to learn is ...........do!
Visit my blog http://inaved-momin.blogspot.com/
Ireneusz Kordal
Ranch Hand

Joined: Jun 21, 2008
Posts: 423
Hello Naved,

try this code:

bat file is not an executable file ( .exe or .com ) , the operating system cannot execute bat, bats can be only executed by the command interpreter.
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3682
    
  16
naved momin wrote:
can you explain me whats wrong here ?

Read the Javadoc for the Runtime.exec() method that you are using and see what each of the parameters represents.


Joanne
naved momin
Ranch Hand

Joined: Jul 03, 2011
Posts: 692

Ireneusz Kordal wrote:Hello Naved,

try this code:

bat file is not an executable file ( .exe or .com ) , the operating system cannot execute bat, bats can be only executed by the command interpreter.

i have read the docs
but still this is also not working ,
now what should be wrong
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3682
    
  16
naved momin wrote:now what should be wrong

You haven't done any research on what the cmd command does and what parameters can be passed to it.

Get that working in a normal command prompt (forget about Java for the moment) and only then should you try and run it from a Java program.
The first thing you should do is type
cmd /?
in your command prompt which will give you a description of how it works.
Charles Hargrave
Greenhorn

Joined: Apr 29, 2010
Posts: 11
naved momin wrote:
but still this is also not working ,
now what should be wrong


I have to agree with Joanne; you need to look at the 'cmd.exe' options.

You have 2 basic typos going on here. When you try to execute programs on any operating system through Java, you NEED to specify the complete file name (including the extension --> cmd.exe).

The other problem is your second argument in the array. It has a slash at the start. Based on previous replies above, it seems you're being recommended to give the 'cmd.exe' program to have a '/C' option, THEN the path to the .bat file. Basically, 3 arguments but you're giving it 2 and those have typos in them.




On Windows, if you get a return code 2 (for missing file), you'll need to fix the path to the file.

CNH
naved momin
Ranch Hand

Joined: Jul 03, 2011
Posts: 692

Charles Hargrave wrote:
naved momin wrote:
but still this is also not working ,
now what should be wrong


I have to agree with Joanne; you need to look at the 'cmd.exe' options.

You have 2 basic typos going on here. When you try to execute programs on any operating system through Java, you NEED to specify the complete file name (including the extension --> cmd.exe).

The other problem is your second argument in the array. It has a slash at the start. Based on previous replies above, it seems you're being recommended to give the 'cmd.exe' program to have a '/C' option, THEN the path to the .bat file. Basically, 3 arguments but you're giving it 2 and those have typos in them.




On Windows, if you get a return code 2 (for missing file), you'll need to fix the path to the file.

CNH

thanks it helps a lot ....
 
Don't get me started about those stupid light bulbs.
 
subject: can't start startup.bat from my application ?