System command and Unix parallelisation

2 views (last 30 days)
hryalexis
hryalexis on 10 Mar 2022
Answered: Al Danial on 21 Apr 2022
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

Answers (1)

Al Danial
Al Danial on 21 Apr 2022
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.

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by