이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
Matlab prevents external program from accessing a file when Matlab script is running
조회 수: 5 (최근 30일)
이전 댓글 표시
Hello,
I am controlling Altair Hypermesh (FEA Program) using MATLAB . My workflow consists of initializing tcl scripts using the command prompt called by MATLAB. The command prompt will open Hypermesh and start the tcl script. One of the tcl scripts that I wrote uploads a file into Hypermesh (.fem file), which was previously edited with MATLAB. However, there is an error in Hypermesh which says that the file does not exist (but it does). This error only occurs if MATLAB is running a script. The .fem file is able to be manually uploaded with no errors only if MATALAB has stopped running.
I believe that the problem has something to do with MATLAB preventing Hypermesh from accessing the .fem file. The function fclose('all') was used to close all files but this does not solve the problem.
Is the source of the problem MATLAB or Hypermesh? My computer is Windows 10 Home edition, so perhaps it is an OS problem?
It would be great if I could receive any advice or solutions.
Thank you
댓글 수: 15
dpb
2018년 9월 19일
I'm guessing the file was open when the session was started and that's when the check for being open occurred. Once the application discovered it couldn't access the file, it probably(?) terminates.
If you subsequently restart the process after closing the file, can it then be opened?
Eric Trudel
2018년 9월 19일
Thanks for the response, the file is closed before calling the command prompt. The issue is that an error occurs when I call Hypermesh from the command prompt using system() in matlab. If I paste the string that would be called by system() into the command prompt, Hypermesh opens and the script functions as expected with no errors.
dpb
2018년 9월 19일
Unless there's some delay between closing the file and the ! command starting a session, I still suspect the OS hasn't got the tables updated yet to indicate the file is no longer open.
Try inserting a pause between and see if that doesn't alleviate the symptom.
Eric Trudel
2018년 9월 19일
I added a pause but that did not seem to prevent any errors. I wrote a secondary script with no opening or closing of any files that simply calls the command string using system() . However, MATLAB is still preventing my Hypermesh script from accessing the .fem file.
Is there a way to unlock a file using MATLAB? or by using the command prompt?
dpb
2018년 9월 19일
"secondary script with no opening or closing of any files that simply calls the command string using system()"
Then it's hardly likely it is Matlab having the file locked that is the problem but more likely that the spawned process isn't operating in the location of the file or doesn't have the same environment variables set that tell the application where to search for files.
Try using a fully-qualified filename.
Eric Trudel
2018년 9월 19일
I have always been using fully-qualified filenames for locating files, both in MATLAB and my tcl script. If I paste the system() command string into the command prompt; the tcl script can open hypermesh then find and upload the .fem files into the application. This does not happen if MATLAB spawned the process using system().
Here is what I have tried;
1. Command string in the command prompt executes the tcl script with no problem.
2. TCL script pasted into the TCL console in Hypermesh has no problems.
3. TCL script run as a script in Hypermesh has no problems.
4. Command string called by MATLAB prevents Hypermesh from accessing certain files. Hypermesh is also unable to upload other files into the gui manually, unless the MATLAB script finishes running.
Note; Both the tcl script and the .fem file are in the same folder.
OCDER
2018년 9월 19일
Just curious, what's the exact script that doesn't work? Copy and paste it to the forum, and comment the section that generates the error.
Eric Trudel
2018년 9월 19일
편집: Eric Trudel
2018년 9월 19일
Here is the matlab script:
%testing
%---%TCL 2 Filename%---%
name_tcl="test.tcl";
folder_path_tcl="C:\Users\e-tru\Documents\";
path2=strcat(folder_path_tcl,name_tcl);
%run command from command prompt, hypermesh opens, then the script begins,
%error occurs when the script wants to upload a .fem file (and a .sh file)
command3=strcat('"C:\Program Files\Altair\2017\hm\bin\win64\hmopengl.exe" -tcl ',' "',path2,'"');
system(char(command3)); %problems start from this line
The TCL script; the error will occur when I use the hypermesh function *ossmooth to upload the needed files. If there is an error, the try-catch statement will exit hypermesh. The problem exists when the script is called from system() in MATLAB (from my understanding):
#threshold values
set solid_domain_threshold 0.700000
set lattice_domain_threshold [expr 1 - $solid_domain_threshold]
#osmooth constrols
set surfacecode 2
set laplacian_iteration 20
set laplacian_feature_angle 25
#"isosurf: surfacecode1 surfacemode2 densitythreshold3 detectbridge4 lowthreshold5 distancecoefficient6 optismoothboundary7 lapiteration8 lapfeatureangle9 lapsmoothboundary10 drawrecovery11"
puts "Uploading Solid Domain"
*createstringarray 2 "isosurf: 3 3 $solid_domain_threshold 1 -1 0 0 10 30 1 1" "other_params: 1 0 0 0 10 0"
###########################################
##ERROR occurs in the line below###########
###########################################
if { [ catch {*ossmooth_12 0 1 0 1 "C:/Users/e-tru/Documents/Altair/Practice/Mult_objective_Stage_2_Practice/Large_Tension_Hinge_Rebuilt_2.2_Stage_2_Initial_1.fem" "C:/Users/e-tru/Documents/Altair/Practice/Mult_objective_Stage_2_Practice/Large_Tension_Hinge_Rebuilt_2.2_Stage_2_Initial_1.sh" "*.grid" 1 0 1 2 } ] } {
puts "Error During Solid Domain Tetmeshing: Refining Mesh"
#exit the console
hm_answernext yes
*quit 1;
hm_answernext yes
} else {
puts "Solid Domain TetMesh Succesful!"
}
OCDER
2018년 9월 19일
"Note; Both the tcl script and the .fem file are in the same folder."
But according to your scripts, your tcl file is here:
"C:\Users\e-tru\Documents\test.tcl"
and your fem file is here:
"C:/Users/e-tru/Documents/Altair/Practice/Mult_objective_Stage_2_Practice/Large_Tension_Hinge_Rebuilt_2.2_Stage_2_Initial_1.fem"
Have you confirmed the location of the TCL file like this?
name_tcl ='test.tcl';
folder_path_tcl ='C:\Users\e-tru\Documents\';
path2 = fullfile(folder_path_tcl, name_tcl);
if ~exist(path2, 'file')
error('Could not find your TCL file at "%s".', path2');
end
command3 = strcat('"C:\Program Files\Altair\2017\hm\bin\win64\hmopengl.exe" -tcl ',' "',path2,'"');
system(char(command3));
Eric Trudel
2018년 9월 19일
I have two tcl scripts; a small one for debugging the section that generates errors and another main script that contains more code. The small script is called "test.tcl". However the small and large scripts generate the same error when executed from MATLAB.
I checked if both the .tcl and .fem files exist, and they return no errors (they exist).
dpb
2018년 9월 19일
"If I paste the system() command string into the command prompt; the tcl script can open hypermesh then find and upload the .fem files into the application. This does not happen if MATLAB spawned the process using system()."
That's the environment then almost certainly...check all environment variables in the command window in which you run interactively and then compare to those in the window when you just execute ! from Matlab.
Eric Trudel
2018년 9월 20일
I checked my environment variables, both within the command prompt and MATLAB, but I don't understand what to look for. The only differences that exists when MATLAB calls the command prompt are the following environment variables below:
KMP_BLOCKTIME=1 KMP_HANDLE_SIGNALS=0 KMP_STACKSIZE=512k KMP_REGISTERED_LIB_15500=00007FFDC9DD7954-cafe3697-libiomp5md.dll
I uploaded a csv file that contains all environment variables for comparison.
A path was also added to the PATH variable that links to the folder with all my files but that did not fix the problem.
dpb
2018년 9월 20일
편집: dpb
2018년 9월 20일
PATH isn't the same as starters--I didn't try to do precise comparison, but
>> p2='Path=C:\Program Files\MATLAB\R2017b\bin\win64;C:\MSC.Software\Patran_x64\20170\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\MATLAB\R2017b\runtime\win64;C:\Program Files\MATLAB\R2017b\bin;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Microsoft VS Code\bin;C:\Users\e-tru\AppData\Local\Programs\Python\Python37-32\Scripts\;C:\Users\e-tru\AppData\Local\Programs\Python\Python37-32\;C:\Users\e-tru\AppData\Local\Microsoft\WindowsApps;'
p2 =
'Path=C:\Program Files\MATLAB\R2017b\bin\win64;C:\MSC.Software\Patran_x64\20170\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\MATLAB\R2017b\runtime\win64;C:\Program Files\MATLAB\R2017b\bin;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Microsoft VS Code\bin;C:\Users\e-tru\AppData\Local\Programs\Python\Python37-32\Scripts\;C:\Users\e-tru\AppData\Local\Programs\Python\Python37-32\;C:\Users\e-tru\AppData\Local\Microsoft\WindowsApps;'
>> strcmpi(p1,p2)
ans =
logical
0
>> length(p1)
ans =
550
>> length(p2)
ans =
591
>>
Also, what is working directory between the two sessions?
Something in there somewhere isn't set up correctly when you're spawning a new session.
You might consider paring back to a "barebones" PATH and other environment that does work in the working session to use as a template for a batch file to dispatch to set the proper environment for the application.
What happens in Windows with "automagic" installers is adding a whole bunch of stuff behind the scenes you're not aware of when install a software package. You need to look at what the particular program needs, specifically, that has been taken care of for you by its installer or batch file or whatever that isn't done the other route.
Eric Trudel
2018년 9월 21일
Alright, turns out the problem was that the working directory changed when I called Hypermesh from MATLAB (went to C:/Windows/System32 not C:/Users/e-tru/Documents ). So I had to change my working directory through my tcl script to C:/Users/e-tru/Documents. Now the script works as intended.
Thank you dpb and OCDER for your help.
Adeline War
2022년 3월 10일
Eric Trudel may I get your help in making a batch process between Matlab and HYpermesh?
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)