Any function like ISDEPLOYED for detection of Web-App mode

조회 수: 2 (최근 30일)
Hiroaki Nakanishi
Hiroaki Nakanishi 2023년 1월 11일
댓글: Kojiro Saito 2023년 1월 11일
English follows Japanese (Bad English, sorry):
今MATLABアプリを作成していて、Webアプリとして実行可能にしたいと思っているのですが、
uigetdirやinputdlgなど、Webアプリとして実行される場合にのみサポートされない関数があります。これらについて、Webアプリとして実行されているかどうかで場合分けをしたいのですがうまくいきません。
uigetdirやinputdlgなどと同等の機能を実現するために、別の方法は用意しました。
そしてWebアプリとして実行されている場合にのみその方法を使い、そうでない場合には通常の関数(uigetdirなど)を使用させたいのですが、「Webアプリとして実行されているか」を判定する関数が見つかりませんでした。try-catchも試しましたが、エラーをキャッチできません。
なにか良い方法、あるいは「Webアプリとして実行されているか」を判定する関数はありますでしょうか?
---
I'm creating an application to execute in Web-App mode and in trouble of detection of execution mode (in MATLAB or WebAppServer/Standalone.)
There are some functions like UIGETDIR or INPUTDLG that DO work in Standalone mode but DON'T in WebApp mode.
I've created alternative ways for those functions, and I wanna write codes which execute them when the app is executed in WebApp mode and execute original ones (UIGETFILE, etc...) otherwise. But I can't find any function which returns 1 only when the app is in WebApp mode.
(ISDEPLOYED returns 1 not only when the app is WebApp mode but also in Standalone mode. If my understanding is wrong, okease tell me.)
I also tried a TRY-CATCH statement below but it dis not work.
Is there any function like that or any way to realize the function?
Any help would be appreciated.
---
Sample Codes:
try
% uigetdir is not supported in WebApp mode, thus I expect that MException occurs here.
d = uigetdir(pwd, 'select folder');
catch
d = uigetdir_WebApp(pwd, 'select folder') % alternative function of uigetdir for WebApp mode
end
% -> try-catch is not working; Error "'uigetdir' is not supported in Web App" occurs.

채택된 답변

Kojiro Saito
Kojiro Saito 2023년 1월 11일
ctfrootという関数を使うと場合分けができます。
スタンドアロンアプリで実行すると、ctfrootは例えばWindowsだと
C:\Users\USERNAME\AppData\Local\Temp\USERNAME\mcrCache9.13\myApp0
のようにmcrcachedirコマンドでリターンされるAppDataのフォルダーになります。
Webアプリで実行すると、ctfrootはWindowsだと
C:\ProgramData\MathWorks\webapps\R2022b\USR\.appCache\mcrCache9.13\myApp0
のように、ProgramDataのフォルダーになります。
これを区別することでWebアプリかどうかの判定ができます。
  댓글 수: 2
Hiroaki Nakanishi
Hiroaki Nakanishi 2023년 1월 11일
ありがとうございます!動作しました。
Kojiro Saito
Kojiro Saito 2023년 1월 11일
回答の採用ありがとうございました。解決して良かったです。

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB Web App Server에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!