是否可以在计算期间暂停 Mathematica 内核?这是一个例子。
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....
...........
...........
]
我可以想出一个Do[..]
循环解决方案不断检查指定目录是否创建了文件。一旦找到文件,它就会读取内容,而 Mathematica 代码的其余部分则处理数据。
有什么优雅的方法来解决这个问题吗?
BR
Try Pause[n]
,暂停至少 n 秒。
Edit:要使其工作不确定的时间,您需要重复轮询文件系统。FileExistsQ
这样做,你会像这样使用它
While[!FileExistsQ[ "filename" ], Pause[1]]
最多也就浪费一秒钟的等待时间。
进一步编辑:您还可以将文件存在性轮询放入批处理文件中,从而释放 Mathematica 会话。例如。创建一个名为 C:\Temp\Test.bat 的批处理文件,其中包含:
@echo off
start /min apame_win64 input
echo Loop commenced %TIME%
:loop
rem wait three seconds
ping localhost -n 3 > nul
if not exist c:\temp\alldone.txt goto loop
rem wait while file is completely written out
ping localhost -n 3 > nul
rem then terminate the process
taskkill /f /fi "imagename eq apame_win64.exe"
exit
并从 Mathematica 调用它:Run["start /min c:\\temp\\test.bat"]
此批处理演示假设 apame_win64 将写出文件 alldone.txt 来完成。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)