2024-04-26 21:04:00 发布
网友
我有一个用C Python语言开发的控制台应用程序。我需要从java代码中调用这个程序函数。此外,我还需要在调用main函数后将一些参数(如List<;gt)传递给它。我研究了一个foundthis链接,但它是针对jpython代码的。我们有类似的C Python工具吗?你知道吗
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; } }
相关问题 更多 >
编程相关推荐