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.

Based on this I'd like to close the mathematica front end without the nagging dialog boxes that follow.

Why am I trying to do this?

I have a bash script which is such:

#!/bin/bash

mathematica bfile01.nb
pid1=$(pgrep mathematica)
    kill -9 $pid1

! [ -z `pidof mathematica` ] || mathematica bfile02.nb
pid2=$(pgrep mathematica)
    kill -9 $pid2

! [ -z `pidof mathematica` ] || mathematica bfile03.nb

So this is just a serial execution of several mathematica files, each of which has an initialization cell in it.

I find that unless I close the front end, the next file doesn't launch and killing the process in the unix terminal didn't quite help (very strange as this only happens with mathematica)

So any thoughts or ideas?

Edit 2: Using a mathematica script file

Here is a mathematica file that I converted into a script: When I chmod it and run it, I get a bunch of error messages which don't allow my figures to be saved from the Plot3D or ContourPlot.

If you try to run the file attached (test3.m), you would want to change the file save path, Export in the last line of the file.

Error messages:

> General::stop: Further output of ReplaceAll::reps will be suppressed
> during this calculation.

Edit 3:

In the test3.m file, I made the following changes:

Changed hSol = to hSol[x_?NumericQ, y_?NumericQ, t_?NumericQ] (file has been uploaded).

This has changed the error messages that I get to:

> Part::partw: Part 3 of InterpolatingFunctionDomain[hSol] does not
> exist.
> 
> Set::shape: Lists {TMin, TRup} and
> InterpolatingFunctionDomain[hSol][[3]] are not the same shape.
> 
> Set::shape: Lists {nX, nY, nT} and {} are not the same shape.

Clearly, when run as a mathematica notebook, I never got these errors.

Edit 4:

I seem to have corrected my errors after Ruebenko's last comment.

the new file is attached here.

Heres the issue that I had:

Once the package was created (.m file), when opened in a text editor, all the lines were commented out with (**) which I don't know why.

However, getting rid of the comments also uncommented some text that I had previously commented so as to not use. That resulted in error messages.

share|improve this question
    
Perhaps this is helpful: ref/program/MathematicaScript –  user21 Aug 15 '12 at 22:38
    
@ruebenko It seems to lack proper documentation though. –  drN Aug 15 '12 at 22:53
1  
seems fully documented to me. This is not a Mathematica function. Have a look in the more into and the tutorial tutorial/MathematicaScripts. –  user21 Aug 15 '12 at 22:55
    
@ruebenko Hmmm... this needs some consideration. Thank you. I didn't quite understand that what you included in your comment was the actual path to the tutorial. Will look into that. However, what if I am compelled to use bash scripting exclusively without turning my mathematica file into a script? (Just playing devils adv.) –  drN Aug 15 '12 at 22:58
1  
Excellent. Have fun with the scripting. –  user21 Aug 16 '12 at 16:53
show 8 more comments

2 Answers 2

up vote 1 down vote accepted

You may want to try MathematicaScrip which was made for exactly this purpose.

Documentation for that is ref/program/MathematicaScript and perhaps tutorial/MathematicaScripts

share|improve this answer
    
Done! :) Hopefully I won't run into too many issues. But obv. I'd still be interested in the front end tokens –  drN Aug 16 '12 at 17:08
add comment

Take a look at: Programmatically quitting the FrontEnd or running without one?

I asked some similar questions and the answers have some good strategies to do this although most of them as workarounds outside of the Mathematica front end.

A simple but key thing, adding

NotebookSave[]

to the end of your initializations cell can avoid some of the problems with pop up dialog boxes.

You may find:

FrontEndTokenExecute["QuitKernel"]  

useful.

But I did not find a way to quit Mathematica with a FrontEndToken even if it directly followed saving the notebook, because unfortunately, executing a single command changes the notebook's state, which then prompts one to save the notebook on exit.

A nice to have -- running a command in a sandbox that wouldn't affect the Front End''s state.

No clue how to do it, but it could prove useful.

In my application I eventually ran a script on a timer and had to gauge when the notebook completed the processing it needed.

One final thought/question. Does your application require the front end to run? You can run the kernel even multiple kernels for parallel processing without a front end.

Some potentially useful links:

share|improve this answer
    
Will read all this and see what seems to do the trick. And then I'll include that here! Thanks! –  drN Aug 16 '12 at 0:24
    
You could use SetOptions[EvaluationNotebook[], "ClosingSaveDialog" -> False] after saving to avoid the save prompt. –  Simon Woods Aug 16 '12 at 8:41
    
@SimonWoods -- Great idea. I didn't know about the setting. Thanks. –  Jagra Aug 16 '12 at 12:03
    
FrontEndTokenExecute["QuitKernel"] Didn't close the notebook... –  drN Aug 16 '12 at 14:23
    
Including the following SetOptions[EvaluationNotebook[], "ClosingSaveDialog" -> False] FrontEndTokenExecute["FrontEndQuit"]; still gave rise to the dialog box :( –  drN Aug 16 '12 at 14:24
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.