I have a console application developed in C Python language. I need to call this program function from my java code. Also, I need to pass some arguments such as List<> to the main function once it is called. I have researched a found this link, but it is for a J Python code. Do we have a similar facility for C Python?
Asked
Active
Viewed 115 times
1 Answers
0
import java.io.IOException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class SystemCall{
private static Log logger = LogFactory.getLog(SystemCall.class);
public static int execute(String command) {
int result = 0;
if (command == null){
throw new RuntimeException("harness command is null");
}
Runtime r = Runtime.getRuntime();
try {
Process p = r.exec(command);
try {
if (p.waitFor() != 0) {
result = p.exitValue();
}
} catch (InterruptedException e) {
logger.error("System call interupted.", e);
//TODO
} finally {
//TODO
}
} catch (IOException e) {
logger.error("IO error in system call.", e);
//TODO
}
return result;
}
}

bpgergo
- 15,669
- 5
- 44
- 68