System function fail to run batch file but shell escape and running in cmd works just fine
Hi I’ve been building an app in Matlab (Matlab 2021b) that requires calling external functions. I’ve been doing this by automatically generating an input batch file that I then send to a system() call to run the appropriate software and inputs.
However, matlab has recently been giving my errors when I run the system() call and fails to execute the external function. If I run the batch file in the cmd window everything works just fine and I get the correct results. If I run the batch file using the shell escape in matlab it also runs just fine and produces the correct results.
The code in question is very simple…
function run_Batch_file(Batch_File)
%run_Batch_file Summary of this function goes here
% Detailed explanation goes here
% DOES NOT WORK – error code 3 system cannot find specified path.
% Here Batch_File = ‘tempSame_Batch_File.bat’
[status, ~] = system(Batch_File, ‘-echo’);
% DOES NOT WORK – error code -1073741819 (no clue what this error code is).
[status, ~] = system(‘tempSame_Batch_File.bat’, ‘-echo’);
% DOES WORK
!tempSame_Batch_File.bat -echo
if status ~= 0
% disp([‘Error: ‘ Batch_File ‘ status code:’])
error(‘Error: %s n status code: %f’, Batch_File, status);
else
fprintf(‘%s status code: %f n’,Batch_File, status);
end
end
The issue on hand is that I’d like to run multiple different bat files through this same script when would mean the batch filename would need to be changed. I cannot change it using the shell escape and the system() call doesn’t work.
Is there any way to either update the shell escape to use variables or is there something I can do to fix the system call (I did find some environment variables were different between the Matlab system call and the cmd system call but isenv and unsetenv are not available in 2021b)?Hi I’ve been building an app in Matlab (Matlab 2021b) that requires calling external functions. I’ve been doing this by automatically generating an input batch file that I then send to a system() call to run the appropriate software and inputs.
However, matlab has recently been giving my errors when I run the system() call and fails to execute the external function. If I run the batch file in the cmd window everything works just fine and I get the correct results. If I run the batch file using the shell escape in matlab it also runs just fine and produces the correct results.
The code in question is very simple…
function run_Batch_file(Batch_File)
%run_Batch_file Summary of this function goes here
% Detailed explanation goes here
% DOES NOT WORK – error code 3 system cannot find specified path.
% Here Batch_File = ‘tempSame_Batch_File.bat’
[status, ~] = system(Batch_File, ‘-echo’);
% DOES NOT WORK – error code -1073741819 (no clue what this error code is).
[status, ~] = system(‘tempSame_Batch_File.bat’, ‘-echo’);
% DOES WORK
!tempSame_Batch_File.bat -echo
if status ~= 0
% disp([‘Error: ‘ Batch_File ‘ status code:’])
error(‘Error: %s n status code: %f’, Batch_File, status);
else
fprintf(‘%s status code: %f n’,Batch_File, status);
end
end
The issue on hand is that I’d like to run multiple different bat files through this same script when would mean the batch filename would need to be changed. I cannot change it using the shell escape and the system() call doesn’t work.
Is there any way to either update the shell escape to use variables or is there something I can do to fix the system call (I did find some environment variables were different between the Matlab system call and the cmd system call but isenv and unsetenv are not available in 2021b)? Hi I’ve been building an app in Matlab (Matlab 2021b) that requires calling external functions. I’ve been doing this by automatically generating an input batch file that I then send to a system() call to run the appropriate software and inputs.
However, matlab has recently been giving my errors when I run the system() call and fails to execute the external function. If I run the batch file in the cmd window everything works just fine and I get the correct results. If I run the batch file using the shell escape in matlab it also runs just fine and produces the correct results.
The code in question is very simple…
function run_Batch_file(Batch_File)
%run_Batch_file Summary of this function goes here
% Detailed explanation goes here
% DOES NOT WORK – error code 3 system cannot find specified path.
% Here Batch_File = ‘tempSame_Batch_File.bat’
[status, ~] = system(Batch_File, ‘-echo’);
% DOES NOT WORK – error code -1073741819 (no clue what this error code is).
[status, ~] = system(‘tempSame_Batch_File.bat’, ‘-echo’);
% DOES WORK
!tempSame_Batch_File.bat -echo
if status ~= 0
% disp([‘Error: ‘ Batch_File ‘ status code:’])
error(‘Error: %s n status code: %f’, Batch_File, status);
else
fprintf(‘%s status code: %f n’,Batch_File, status);
end
end
The issue on hand is that I’d like to run multiple different bat files through this same script when would mean the batch filename would need to be changed. I cannot change it using the shell escape and the system() call doesn’t work.
Is there any way to either update the shell escape to use variables or is there something I can do to fix the system call (I did find some environment variables were different between the Matlab system call and the cmd system call but isenv and unsetenv are not available in 2021b)? system, shell escape, batch files MATLAB Answers — New Questions