'subprocess.run produces different result if launched from Python, versus Matlab

I have a Python 3 class that creates input to send to a fortran program (xfoil). I am using subprocess.run to launch the fortran binary and send the command inputs to the program, and this works just fine if I do it from within Python. Commands are sent to the fortran program, output is captured, all is well.

Unfortunately, I am trying to make the Python code available from Matlab and it seems to work differently when launched that way. And yes, I've managed to get the paths set up correctly so Matlab will load the Python class and I can call some methods (that don't depend on the fortran run) attached to that class from within Matlab.

My call from Python specifies utf8 encoding (fixed an issue migrating from PC to Mac), and I would assume is pretty plain-vanilla:


    # connect the subprocess for xfoil
    p = subprocess.run(binfile, input=cmds,
                       shell=True, encoding='utf8',
                       stdout=subprocess.PIPE,
                       stderr=subprocess.PIPE)

The commands that get sent to the program make it create an output file. I know I am working in the correct working directory before the call to xfoil because I manage the directories and print them on a debug statement earlier. This location is correct whether I run launching from Python or from Matlab. The difference is that when I run from Python, xfoil creates the expected output file, but if I run from Matlab, xfoil never appears to run at all, and no output file is created.

Thoughts on why there would be a difference? I am on macOS BigSur, Python 3.8.10, and Matlab R2021a

I realize this may be a better question for the Matlab forum because it may be highly dependent on the way Matlab's Python implementation functions.

Thanks in advance!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source