Hi.
I try to get output value of C ILE program that running on AS400, from Java Code.
Here the C ILE code and the Java Code.
The following C ILE code:
Thanks,
Tomer Sasson
I try to get output value of C ILE program that running on AS400, from Java Code.
Here the C ILE code and the Java Code.
The following C ILE code:
PHP Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#pragma argument(main, VREF, nowiden)
int main(int argc, char *argv[]) {
int i;
printf("\nNumber Of Arguments Passed: %d\n", argc);
for (i = 0; i < argc; i++) {
printf("arg[%d]=%s\n", i, argv[i]);
}
printf("----------------------\n");
/* Display parameters sent to the program. */
printf("Incoming parameter 1 = %s\n", argv[1]);
printf("Incoming parameter 2 = %s\n", argv[2]);
printf("----------------------\n");
/* Concatenate the two incoming parameters */
argv[3] = (char*) malloc(20);
memset(argv[3], '\0', 20);
strcpy(argv[3], argv[1]);
strcat(argv[3], argv[2]);
printf("Out parameter 3 = %s\n", argv[3]);
return 0;
}
---------------------------------------------------------------------
The Java code
I want to get argv[3] as output in Java Program:
public class CPgmCaller1 {
private static QSYSObjectPathName PGM = new QSYSObjectPathName("MY#LB", "C_TEST4", "PGM");
/**
* @param args
* @throws DaoException
*/
private static String executeProgramCall(AS400 as400Object, String val1, String val2) throws Exception {
int systemCCSID = as400Object.getCcsid();
CharConverter conv = new CharConverter(systemCCSID);
if (conv == null)
return null;
ProgramParameter[] parameterList = new ProgramParameter[3];
String result = "XXXXXXXXXXXXXXXXXXXX";
parameterList[0] = new ProgramParameter(ProgramParameter.PASS_BY_REFERENC E, conv.stringToByteArray(val1 + '\0'));
parameterList[1] = new ProgramParameter(ProgramParameter.PASS_BY_REFERENC E, conv.stringToByteArray(val2 + '\0'));
parameterList[2] = new ProgramParameter(ProgramParameter.PASS_BY_REFERENC E, conv.stringToByteArray(result.toString()));
ProgramCall programCall = new ProgramCall(as400Object);
programCall.setProgram(PGM.getPath(), parameterList);
if (!programCall.run()) {
System.err.println("Error Calling C Program: " + PGM.getPath());
return null;
}
// This line - return null;
// Should return the concatination of val1 and val2
byte[] resultOutput = parameterList[2].getOutputData();
// This line - return "XXXXXXXXXXXXXXXXXXXX";
byte[] resultInput = parameterList[2].getInputData();
return new String(resultInput);
}
}
//----------------------------------------------------------------------------
Tomer Sasson