MATLAB: Web App Using System Command To Write File

systemsystem commandweb app

Howdy,
I am trying to use system("command") to execute an external program (.exe running on Windows) which writes out files. The app works fine normally. I run the code as an app, I press a button, it executes system("command"), this "command" runs external_program.exe, external_program.exe writes out a file, and everything works as intended. It is only when it is used as a webapp that it does not work. The external_program.exe dose not write out successfully when being executed by a webapp using system("command").
I can have the webapp output the exact system "command" its trying to run, copy that command, run that command in a command prompt, and it works as intended. So I know it has to do something with the webapp.
I ran the following matlab code:
getenv('USERNAME')
getenv('programdata') %directory for program specific data
getenv('appdata') %directory for user specific data (roaming)
getenv('localappdata') %directory for user specific data (local)
getenv('userprofile') %current user profile folder
I get the following response when it is ran as an app:
ans = 'owner123'
ans ='C:\ProgramData'
ans ='C:\Users\owner123\AppData\Roaming'
ans ='C:\Users\owner123\AppData\Local'
I get the following response when it is ran as an webapp:
ans = 'MwWebAppWorkerR2020a'
ans ='C:\ProgramData'
ans ='C:\Users\MwWebAppWorkerR2020a\AppData\Roaming'
ans ='C:\Users\MwWebAppWorkerR2020a'
I thought maybe this is a permission issue. So I moved the external_program.exe file to 'C:\Users\MwWebAppWorkerR2020a', change the ownership of external_program.exe to 'MwWebAppWorkerR2020a', gave "full control" (permission wise) for "everybody" including the following users: "MwWebAppWorkerR2020a", "MwWebAppServerR2020a", "MwWebAppAuthorsR2020a".
After doing this, I still can not get the webapp to use system("command") to execute external_program.exe properly where it writes out files successfully.
I'm thinking maybe I didn't do the permissions properly or when the external_program.exe tries to write out it can not write because how it is ran with permission incorrectly. Any advice on how to overcome this? Or how can I get the webapp to run the system("command") successfully like how it does in app form?

Best Answer

https://www.mathworks.com/matlabcentral/answers/630989-web-app-using-system-command-to-write-file#comment_1100734
Related Question