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?

5 件のコメント

Mario Malic
Mario Malic 2020 年 10 月 30 日
Try giving full control to the folder your program writes in.
Kev K
Kev K 2020 年 10 月 30 日
Thank you, Mario, for your reply. I have double checked the folder has full control
I have given full control, and it still can't write out to the folder. Any other idea what it could be?
Mario Malic
Mario Malic 2020 年 10 月 30 日
Alright, can you check what is current directory (cd) of the web app when it runs (sorry, I have never worked with it, so this might look like a silly question)? At least in my case, temporary/session files from the external program are generated in cd before they are saved to the specified folder. Are you using fullpaths in system command?
Kev K
Kev K 2020 年 10 月 31 日
Hi Mario,
Thank you for your response and help Mario. I figured it out, but before I explain, I will answer your questions.
I was using full paths and enviroment variables. So for example, I used getenv('userprofile') in the matlab code. The external program was writing out to this specific path as well.
I didn't realize the external program was using /C as a temp as well use /c/windows/fonts. Since the "MwWebAppWorkerR2020a" user was executing the external_program.exe, it was trying to access files and folders that only an admin should be able to. So I gave the user "MwWebAppWorkerR2020a" full control to all of /C. This allowed the external_program.exe to do its thing as well the rest of my code which uses the files it generates.
Of course this is probably a security risk, but for my use case, this will only be temporary as it will eventually be turn into a restful api.
Thanks agian Mario for helping and getting me to think outside the box.
Kev
Mario Malic
Mario Malic 2020 年 10 月 31 日
That's great! You're welcome.
It would be great if you could just post a reference to your comment in answer section and accept it, so it's clear for other people who may encounter an issue similar to yours.

サインインしてコメントする。

 採用された回答

Kev K
Kev K 2020 年 12 月 13 日

0 投票

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

1 件のコメント

Mario Malic
Mario Malic 2020 年 12 月 13 日
編集済み: Mario Malic 2020 年 12 月 13 日
I wanted to make an update on this. It is possible to have a better control of the program you're calling with System.Diagnostics.Process. There's a property called StartInfo.WorkingDirectory that could be really useful in your case. There's an example here, without WorkingDirectory.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Introduction to Installation and Licensing についてさらに検索

質問済み:

2020 年 10 月 30 日

編集済み:

2020 年 12 月 13 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by