3
$\begingroup$

I plan to run a lengthy Mathematica script on a Linux terminal (by "a Linux terminal," I mean that I have text output only -- no GUI), using the program math. To be able to track the execution progress of my script, I would like to Print "success messages" to the terminal when no errors or warnings have been thrown by Mathematica in the current session.

For example, here is a very basic script that Imports two text files, test1.txt and test2.txt, using the "Table" specification. I would like to write a function or expression that sets the variable success to True when no error or warning messages have yet been thrown by Mathematica.

Import["test1.txt", "Table"]
success = f;
If[success, Print["test1.txt import successful!"];, Print["General failuire!"];];

Import["test2.txt", "Table"]
success = f;
If[success, Print["test2.txt import successful!"];, Print["General failure!"];];

where f is a function or expression that evaluates to True when no error or warning messages have yet been thrown by Mathematica.

Please note that I am not trying to write a function or expression f that determines if test1.txt or test2.txt exists. Rather, I am trying to write an f that determines whether any errors or warnings at all have been thrown during the current Mathematica session. If any have been thrown prior to when f is called, then success should always be set to False, for the remainder of the Mathematica session.

Do you have any advice on this? Thank you for your time.

$\endgroup$

1 Answer 1

6
$\begingroup$

What you look for is the function Check which will give you the possibility to implement what you ask for in several variants, the most simple probably be this:

success=Check[Import["test1.txt", "Table"];True, False]

See the documentation of Check for more details...

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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