• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to Run a batch file???

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All!
I am trying to run a batch file �Mine.bat� from Java file �Helpme.java� I have written in batch file
D:\
cd javadoc
javac Myprog.java
java Myprog
But when I try to run it (�Mine.bat�) from �Helpme.java� by using,

String str[]={�Mine.bat�};
Process proc;
try{
proc=Runtime.getRuntime().exec("str");
}catch(Exception e){
System.out.println("Exception is raised");
}
The out put results in only the change of directory that is from c:\ it goes to D:\ and program stops instead of running whole Mine.bat, plz tell me what to do? My goal is to compile another java file that is �Myprog.java� from �Helpme.java�.
Files contain in the following directories.
C:\Mine.bat
C:\ Helpme.java
D:\javadoc\Myprog.java
I am using Windows me
I will wait for reply.
bye
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know how it'll help you, but when you run bat file
from other bat you should use "call filename.bat" instead of
"filename.bat".
Alex.
 
Shahbaz Khan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no I want to run a batch file from java file
 
Shahbaz Khan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can u plz send me the coding how to run a batch file from java file it is not working properly only directory is changed
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does the bat file work if you run it by hand from the d:\javadoc directory?
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The batch file would not have worked properly because of the reason that 'd:\'. It should be actually 'd:'. Then, the directory change will happen and rest will follow.
 
Shahbaz Khan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

My batch file is at C:\ and My java file "Helpme.java" is also at c:\ I am compling the file" Helpme.java" from c:\ but "Helpme.java" file is not running my batch file"Mine.bat" the result is only the change of directory that is D:\ when I run it from hand that is by using mouse then it works ok.
But not from "Helpme.java"'s codding.
I am making a compiler and I am very desperate to solve this problem.
thank you for ur consideration,
 
Shahbaz Khan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Mo Ibrahim:
The batch file would not have worked properly because of the reason that 'd:\'. It should be actually 'd:'. Then, the directory change will happen and rest will follow.


No Ibrahim its also not working now the output is only a cursor blinking and prgram is stoped just like waitting for an IO operation.
 
Shahbaz Khan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
plz help me!!
I am waitting for any solution!!
 
Mo Ibrahim
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is your path setting the same when you run manually and from the java program?
 
Shahbaz Khan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of All Thank U Ibrahim for helping me
Path setting are different means My batch file is located at C:\
and I am compling the java file from C:\ and in batch file it is written to compile and run a javafile which is located in D:\javadoc\
Thank u again very much for ur concern about my problem coz I was thinking that I am left alone by the java experts running this services.
 
Check your pockets for water buffalo. You might need to use this tiny ad until locate a water buffalo:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic