0001 function [status, result] = dmri_system(command, arg2)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 if ~(nargin == 1 || nargin == 2)
0013 error('Please check function usage.');
0014 end
0015
0016
0017
0018
0019 dmri_setenv;
0020
0021
0022 sh_file = [tempname, '.sh'];
0023 isok = dmri_script_file_create(sh_file);
0024 if isok == false
0025 error('Failed to create temporary shellscript file: %s', sh_file);
0026 end
0027
0028
0029
0030 if strfind(command, 'fslview ')
0031 [s, r] = dmri_system('which fslview_deprecated');
0032 if s == 0 && ~isempty(r)
0033 command = strrep(command, 'fslview ', 'fslview_deprecated ');
0034 end
0035 end
0036
0037
0038 fid = fopen(sh_file, 'a');
0039 if fid == -1
0040 error('Failed to open temporaryh shell script file: %s', sh_file);
0041 end
0042 fprintf(fid, '%s\n', command);
0043 fclose(fid);
0044
0045
0046 if exist('arg2', 'var')
0047 [status, result] = system(sh_file, arg2);
0048 else
0049 [status, result] = system(sh_file);
0050 end
0051 if status ~= 0 && ~isempty(result)
0052 ix = strfind(result, ':');
0053 result2 = result(ix(end-1):end);
0054 disp(['dmri_system(''', command ''');']);
0055 warning('dmri_system: Failed to execute command.\n reason: %s', result2);
0056 end