Executing Fastload through Java Hang in unix

General
Enthusiast

Executing Fastload through Java Hang in unix

Hi All,

When we try to execute simple Fastload script through Java in unix , it hangs .
same when We tried executing it manually through fastload command "fastload < /temp/data/fastload.txt > /temp/data/fastload.log" it works fine.

Given script which we used it for testing

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class FastLoadTest {
public static void main(String a[]){
int rc = 0;
try {
String cmd = "fastload < /temp/data/fastload.txt > /temp/data/fastload.log";
System.out.println(cmd);
Process p = Runtime.getRuntime().exec(cmd);
rc = p.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = reader.readLine();
while (line != null) {
System.out.println(line);
line = reader.readLine();
}

} catch (Exception e) {
System.out.println(e.getMessage());
}
System.out.println(rc);
}
}

Need your help.

Thanks
3 REPLIES
Teradata Employee

Re: Executing Fastload through Java Hang in unix

There are at least a couple of problems with your program.

First, you are using the shell IO redirect operators in your command. Those are only implemented by the shell. If you want to use them, then you need to run a shell, not fastload directly.

String cmd = "sh -c \"fastload < /temp/data/fastload.txt > /temp/data/fastload.log\"";

Second, why are you getting the Process object's InputStream and reading from that? That doesn't make any sense, since you are redirecting the output to a file.
Enthusiast

Re: Executing Fastload through Java Hang in unix

Thanks a lot. It's working now.

Re: Executing Fastload through Java Hang in unix

hi

I am facing a similar situation where we invoke fastload in a Java program using process builder on unix platform. We read inputStream and write to a log file. Also, using outPurStream we try to write script to fastLoad process. And then we wait for fastload process to finish. But it hangs waiting for fastload process.

Any help.. Thanks