I am trying to run some Matlab Code on an URL that I retrieve from a Firefox Native Messaging app. I use a python script that uses the Matlab engine to run my scripts. This works perfectly fine:
import matlab.engine
import sys
import struct
import time
import subprocess
import logging
# Function to receive Message
def getMessage():
rawLength = sys.stdin.buffer.read(4)
print(rawLength)
if len(rawLength) == 0:
sys.exit(0)
messageLength = struct.unpack('@I', rawLength)[0]
message = sys.stdin.buffer.read(messageLength).decode('utf-8')
eng = matlab.engine.connect_matlab()
eng.workspace['url'] = message
eng.eval('myMatlabFunc(url)', nargout=0)
getMessage()
Now I want to check if Matlab is running and if not start it:
if not matlab.engine.find_matlab():
subprocess.run('C:\\Program Files\\MatlabR2020b-64bit\\bin\\matlab.exe')
This works and I can run my code afterwards as well:
eng = matlab.engine.connect_matlab()
eng.workspace['var1'] = '1'
But then I encounter a strange behaviour, that I cant explain.
As soon as the script is finished, Matlab exits without a Warning/Crash/Exception... The weirdest part is, that this only happens if I run the skript via the native messaging connection.
If I run the script in Pycharm, everythin works as expected.
I hope someone here can help me figure this out!
Thanks, Ben
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.