• 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

batch file problem

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how to execute batch file from java
i have tried with below sample.butwhen i execute this sample no output is comming.please tell me where the problem is

public class bat
{
public static void main(String args[]) throws Exception
{
Runtime r=Runtime.getRuntime();
System.out.println("Before executing batch file");
Process p=r.exec("d:\\puvvada\\servlets\\a.bat");
System.out.println("after executing batchfile");
}
}
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you mean by "no output is coming"? Do you at least see the message "Before executing batch file"? If not, I'm not sure what the problem is. If you see this message, but you don't see the message "after executing batchfile", then perhaps your batch file is still executing. I suggest that you add echo commands to your batch file to see how far it gets in its execution.

If you still can't find the problem, please post your batch file and we will try to help.

Layne
 
pvsr rao
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when i execute this program dospopup is not comming. before executing batchfile and after executing batchfile statements are printing.just the dospopup window is not displaying
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try usingIf you want the DOS window to stay open after the batch file has completed, replace the /C with /K.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Carefully read the Javadocs for java.lang.Process
In particular note what it says about the handling of output from the process - if your bat process is trying to produce output and you are not handling it properly the process will hang indefinately.
This has been discussed frequently on this forum so do some searching.
Bill
 
pvsr rao
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thankyou for sending,it's working fine
 
pvsr rao
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when iam trying to execute
Runtime r=Runtime.getRuntime();
Process p=r.exec("java.exe")
no output is comming.
whether we have to give any commandor is it right.please tellme the solution
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See William's post above.
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have one problem when iam trying to execute this statement dos window is not comming
Process p=r.exec("cmd /C c:/raju/a.bat");
when i come out of the program and when i gave a.bat
it is working.plese tellme how to do this
 
It's fun to be me, and still legal in 9 states! Wanna see my tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic