shkk13 said:
Hello gurus,
Would anybody let me how to call informix-4gl program from java?
Please show this with a simple example if possible. I use character
interfaced 4GL, not GUI enabled D4GL. I would welcome any feedback in
this regard. Thanks.
I have no idea what that is, but pretty much any program that can be
called from the DOS command line (or Unix) can be executed using
Runtime.exec.
A small example - my code that calls a process. Both servers are
Solaris. (Modified for sensitive content.)
import java.io.*;
import java.net.*;
public class callForeignServer
{
public static void main(String[] args) throws IOException
{
String [] command = {"rsh","-l","username",
"remotemachine.com",
"pathToCommand/command arg1 arg2 arg3"};
String results="";
String error="";
String s;
try
{
Process p = Runtime.getRuntime().exec(command);
InputStream in1 = p.getInputStream();
InputStream err1 = p.getErrorStream();
BufferedReader in = new BufferedReader(new InputStreamReader
(in1));
BufferedReader err = new BufferedReader(new InputStreamReader
(err1));
// read the output from the command
System.out.println("Here is the standard output of the command:
\n");
while ((s = in.readLine()) != null)
{
System.out.println(s);
}
// read any errors from the attempted command
System.out.println("Here is the standard error of the command
(if any):\n");
while ((s = err.readLine()) != null)
{
System.out.println(s);
}
p.waitFor();
System.out.println(p.exitValue());
}
catch (Exception e)
{
System.err.println(e.getMessage());
System.exit(1);
}
}
}
--