• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

batch file problem

 
pvsr rao
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • 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");
}
}
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • 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.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13055
6
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thankyou for sending,it's working fine
 
pvsr rao
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
See William's post above.
 
trinadh reddy
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic