Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have gotten a tremendous amount of information from the question posted at (Load a Mathematica Package via .Net code), which my application is very similar to. Specifically in that thread, the author uses:

MathKernel k = new MathKernel();  //Establishes a Mathematica kernel  
k.Compute("<< XYZ`XYZGraphs`");   //Runs an entire package file   
string res = k.Result.ToString(); //Collects the result of the file

I was wondering if there was a similar process for a Notebook file? When I tried referencing a Notebook file in the same manner, the math kernel returns $Failed as the result.

Other solutions I thought might work but have not had any success with have been using IKernelLink and IMathLink, or converting the Notebook file to a Package file. I also saw a thread about running from the command line but I am not sure how I would get the results of the Notebook back into .Net using that method.

I would greatly appreciated any advice, thanks!

share|improve this question
    
Notebooks contain a lot of content which doesn't mean anything to the Kernel, they're loaded by the FrontEnd. This is the process you can see running called Mathematica rather than MathKernel when you run Mathematica directly. In interactive operation the frontend sends expressions to the kernel from a notebook. –  Ymareth Jan 30 at 16:40
1  
As Ymareth said, notebooks are not made for this purpose and you should not try to use them this way. You were on the right track when you were thinking of converting the notebook to a package (i.e. plain text file with .m extension and Mathematica commands within). How to do that is explained here. –  Szabolcs Jan 30 at 16:50
    
@Szabolcs That is exactly the type of information I needed to move forward. Thank you! –  Josh Jan 30 at 17:03
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.