Execute .m file with JLink
- To: mathgroup at smc.vnet.net
- Subject: [mg109742] Execute .m file with JLink
- From: Daryn <darynholmes at gmail.com>
- Date: Fri, 14 May 2010 05:36:30 -0400 (EDT)
We would like to execute a .m file, with JLink against Mathematica Player Pro 7. We are not sure if it is our java code or if the problem is in the .m file. We can execute simple statements directly from the java program with JLink but we get no output from a .m file (we expect the output to be a csv-file written by Mathematica). Here is our Java code: ------------ String[] myArgs = { "-linkmode", "launch", "-linkname", "math -mathlink" }; KernelLink ml = null; try { ml = MathLinkFactory.createKernelLink(myArgs); } catch (MathLinkException e) { System.out.println("Fatal error opening link: " + e.getMessage()); return; } try { // Get rid of the initial InputNamePacket the kernel will send // when it is launched. ml.discardAnswer(); String mpath = "<<"+<m-file-path>; // String mpath = <m-file-path>; // we also tried this ml.putFunction("EvaluatePacket", 1); ml.putFunction("Get", 1); ml.put(mpath); ml.endPacket(); int packet = ml.waitForAnswer(); System.out.println(packet); System.out.println(ml.errorMessage()); System.out.println("Done!"); } catch (MathLinkException e) { System.out.println("MathLinkException occurred: " + e.getMessage()); } finally { ml.close(); } ------------ On the console we get: 3 everything ok so far Done!