• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Kok Hwa Koh
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Dan Walin
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic