File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes How to call a program to run back-end ? Please Help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to call a program to run back-end ? Please Help" Watch "How to call a program to run back-end ? Please Help" New topic
Author

How to call a program to run back-end ? Please Help

Kok Hwa Koh
Greenhorn

Joined: Jan 08, 2004
Posts: 2
I am kokhwa. I have meet problem to call a program to run back-end.
I want to call ztc to run at back-end, but I dont know how to do it! I hope anyone who has experience or know about it to help me. Thanks a lot.
ztc is a Z typechecker. ztc running using dos prompt. if the path is "c:/ztc/" , we need to type command like this "ztc filename.zed" to run ztc. after that, ztc will generate a file call "filename.log", after that i have to read a the *.log file to generate another file...That is my problem!
anybody know how to solve this problem?
Thanks for your help!
Chris Harris
Ranch Hand

Joined: Sep 21, 2003
Posts: 231
Hi kokhwa,
Welcome to the Java Ranch.
Here is my understanding of you problem:
1. You need to execute an external program called ztc from you java program. This can be done using Runtime.exec(). The method parameters are what you put on the normal command line. You also need to tell the method the shell that the program is going to run in. This is different depending on the platform you are using i.e NT = CMD, 98 = command , and unix has many different types. If you do need more help just ask.
2. You then need to wait for the ztc to generate the file you are going to process. I would recommend that you create a thread that probes that directory and then process when the file appears.
Hope that help.
If you have any questions, just ask.
Chris.


SCJP 1.2, SCWCD, SCBCD
Dan Walin
Ranch Hand

Joined: Nov 11, 2003
Posts: 109
Here's an example in which I had to do something similar using the Runtime class. There may be more code here than you need but one problem I found was that I could not determine when the called program completed so I loop checking
the length of a file. When that file length changes, it tells me that the called program has completed.
xmlfile = inputlist[i];
cmd[0] = "cmd.exe";
cmd[1] = "/K";
cmd[2] =
"acxmlai -i:j:\\xmlfiles\\"
+ xmlfile
+ " -l:c:\\import\\xmllog.txt -u:"
+ id
+ " -p:"
+ pass;

int exitval;
File ckfile = new File("j:\\xmlfiles\\" + xmlfile);
File finishfile = new File("j:\\done\\" + xmlfile);
long f1len = ckfile.length();
try {
proc = Runtime.getRuntime().exec(cmd);
System.out.println("waiting for process to complete");
while (f1len >= ckfile.length()) {
try {
wait(5000);
}
catch (InterruptedException e) {
System.out.println("exception on wait");
}
System.out.println("waiting for xml auto import to complete. . . ");
try {
wait(5000);
}
catch (InterruptedException e) {
System.out.println("exception on wait");
}
}
}
catch (IOException ex) {
System.err.println("Exception, executing" + ex.getMessage());
ex.printStackTrace();
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to call a program to run back-end ? Please Help