Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

can't start startup.bat from my application ?

 
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Ranch Hand
Posts: 423
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 11
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ....
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic