Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

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!


  • Prev by Date: Re: How to write reports and books in Mathematica
  • Next by Date: Re: GeometricTransformation causes dislocated
  • Previous by thread: Re: innerApply[{f, g}, {{a, b}, {c, d}}] = {f[a, b], g[c,d]} ?
  • Next by thread: Re: Execute .m file with JLink