aspose file tools*
The moose likes Java in General and the fly likes batch file problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "batch file problem" Watch "batch file problem" New topic
Author

batch file problem

pvsr rao
Ranch Hand

Joined: Oct 05, 2005
Posts: 102
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

Joined: Dec 06, 2001
Posts: 3061
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


Java API Documentation
The Java Tutorial
pvsr rao
Ranch Hand

Joined: Oct 05, 2005
Posts: 102
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

Joined: Aug 05, 2005
Posts: 3742
    
  16
Try usingIf you want the DOS window to stay open after the batch file has completed, replace the /C with /K.


Joanne
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
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

Joined: Oct 05, 2005
Posts: 102
Thankyou for sending,it's working fine
pvsr rao
Ranch Hand

Joined: Oct 05, 2005
Posts: 102
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

Joined: Aug 05, 2005
Posts: 3742
    
  16
See William's post above.
trinadh reddy
Ranch Hand

Joined: Sep 22, 2005
Posts: 60
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: batch file problem