Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can't start startup.bat from my application ?

 
naved momin
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
Ireneusz Kordal
Ranch Hand
Posts: 423
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
naved momin
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3742
16
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic