System command and Unix parallelisation
조회 수: 5 (최근 30일)
이전 댓글 표시
Dear Matlab Community,
I am writting an application to process Earth Observation remote sensing data. My application written in Matlab aims to control other applications written in Python and Bash.
So my Matlab scripts create a bash script named scripttoeval.sh and I use the system command to execute this script.
% In my scripts
system('scripttoeval.sh')
The scripttoeval.sh contains a single command:
% In Matlab terminal
!more scripttoeval.sh
cd worddirectory
run_step_1.sh
And the run_step_1.sh contains several python commands:
% In Matlab terminal
!more run_command_1.sh
python3 command_to_do processing_01.txt
python3 command_to_do processing_02.txt
python3 command_to_do processing_03.txt
python3 command_to_do processing_04.txt
...
It works perfectly. The processing_0X are option files.
However I would like to add a "parallelisation" option and in this case I use another file named run_command_1_para.sh.
% In Matlab terminal
!more run_command_1_para.sh
python3 command_to_do processing_01.txt &
python3 command_to_do processing_02.txt &
wait
python3 command_to_do processing_03.txt &
python3 command_to_do processing_04.txt &
...
wait
So I replace run_command_1.sh with run_command_1_para.sh. Here, the behaviour is abnormal:
- if system('scripttoeval.sh') runs and completes the processing: all is well.
- if system('scripttoeval.sh') fails or I stop the processing by Crtl+c touchs: the Unix ls command is modified. In Matlab terminal, ls command returns the abnormal outputs: the list of files/directories and displayed outputs from the python commands (verbose).
Firstly, I thought the error was related to command_to_do, but when I run scripttoeval.sh directly in Unix terminal and stop, no error. For me, the errors are caused by the Matlab system command, and changes the Unix system environment in Matlab. Why?
Thanks in advances,
Kind regards,
Alexis
댓글 수: 0
답변 (1개)
Al Danial
2022년 4월 21일
Independently of MATLAB, can you run run_command_1_para.sh directly from a Unix terminal and get the behavior you want? If that works, try system('run_command_1_para.sh') in MATLAB, then build up the layers of script invocations until you're at the level you want.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Package MATLAB Functions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!