I am creating various matlab .m-files with python and then run them using subprocess. When the files are finished I would like to delete them:
command = ['C:\\MatlabR2012b\\bin\\matlab.exe', '-nodesktop', '-nosplash', '-r', 'mfile']
matlab = subprocess.Popen(command) # launch matlab with m file
matlab.wait() # wait for matlab to finish before deleting .m file
print "delete"
os.remove(self.filename)
The problem is that matlab.wait() never waits, since matlab returns exit code 0 immediately. Is there another way to check if matlab has finished?
On Windows, there is both
bin\matlab.exe
andbin\win32\matlab.exe
(orbin\win64\matlab.exe
). The former is just a wrapper around the latter and pretty much exits immediately.You can either call
bin\win32\matlab.exe
directly or use the-wait
option when callingbin\matlab.exe
.