Is it possible to pause Mathematica kernel during a computation? Here is an example.
Module[{},
Mathematica code....
..........
..........
{
Calls an external program with some argument
Needs to wait for an external program to create a file (* How ?*)
}
Mathematica code using that file content....
...........
...........
]
I can come up with a Do[..]
loop solution that keeps on checking in a specified directory whether a file is created or not. Once it finds the file it reads the content and rest of the Mathematica code processes the data.
Is there any elegant way to solve this problem?
BR
You call an external program, does that program exit once the file is created? If so, then RunThrough is what you're looking for, see the RunThrough example. There they use another instance of Mathematica as the external program (like executing a Mathematica script and waiting for its result).
If the external program has to remain running after the file was created then you can use a separate script (shell script, python, ruby...) to check if the file exists.
Try
Pause[n]
, pauses for at least n seconds.Edit: to make it work for an indeterminate amount of time, you need to repeatedly poll the filesystem.
FileExistsQ
does this, and you'd use it likewhich would at most have one second of wasted time while waiting.
Further Edit: You can also put the file existence poll in a batch file thereby freeing up your Mathematica session. E.g. make a batch file called C:\Temp\Test.bat containing:
And call it from Mathematica:
Run["start /min c:\\temp\\test.bat"]
This batch demo assumes apame_win64 will write out a file alldone.txt to complete.