Staf Java 接口 编程
Step1:
创建STAFHandle
STAFHandle handle = new STAFHandle("MyApplication");
Step 2:
组建命令然后提交
String machine = this.ip;
STAFResult result = handle.submit2(machine, service, request);
String service = "PROCESS";
String request = "START SHELL COMMAND " +
STAFUtil.wrapData(command) +
" WAIT RETURNSTDOUT STDERRTOSTDOUT
STAFResult result = handle.submit2(machine, service, request);
Step 3
分析结果:
Map resultMap = (Map)result.resultObj;
String processRC = (String)resultMap.get("rc");
if (!processRC.equals("0"))
{
logger.error( "ERROR: Process RC is not 0.\n" + result.resultContext);
return stdoutData;
}
// Print the stdout/stderr data for the command
List returnedFileList = (List)resultMap.get("fileList");
Map stdoutMap = (Map)returnedFileList.get(0);
stdoutData = (String)stdoutMap.get("data");
logger.info( "the get data:" + stdoutData);
一个完整的例子
import com.ibm.staf.*;
import java.io.*;
public class STAFTest
{
public static void main(String argv[])
{
try
{
// Create a STAFHandle
STAFHandle handle = new STAFHandle("MyApplication");
System.out.println("My handle is: " + handle.getHandle());
try
{
// Submit a synchronous request to the ECHO service on
// the local machine
STAFResult result = handle.submit2(
"local", "ECHO", "ECHO Hello");
if (result.rc != 0)
{
System.out.println(
"ERROR: STAF local ECHO ECHO Hello failed. RC: " +
result.rc + ", Result: " + result.result);
}
else
{
System.out.println("ECHO Result: " + result.result);
}
// Or submit an asynchronous request to the ECHO service on
// the local machine
result = handle.submit2(
STAFHandle.ReqRetain, "local", "ECHO", "ECHO Hello");
if (result.rc != 0)
{
System.out.println(
"ERROR: STAF local ECHO ECHO Hello failed. RC: " +
result.rc + ", Result: " + result.result);
}
else
{
System.out.println(
"Asynchronous ECHO Request number: " + result.result);
}
}
finally
{
handle.unRegister();
}
}
catch (STAFException e)
{
System.out.println(
"Error (un)registering with STAF, RC:" + e.rc);
System.exit(1);
}
} // End of main()
} // End of STAFTest
更多的refer to