Home > utils > execute_unix.m

execute_unix

PURPOSE ^

[varargout] = execute_unix(unix_str,nout,errmsg,logfid);

SYNOPSIS ^

function [status,varargout] = execute_unix(unix_str,nout,errmsg,logfid)

DESCRIPTION ^

 [varargout] = execute_unix(unix_str,nout,errmsg,logfid);

 Executes a command in the UNIX shell and returns results

  unix_str - command to be executed
  nout - The expected number of output arguments 1=return status only
  errmsg - The string to be displayed if the command fails.
  logfid - The file ID where the command should be echoed. Default is stdout.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [status,varargout] = execute_unix(unix_str,nout,errmsg,logfid)
0002 % [varargout] = execute_unix(unix_str,nout,errmsg,logfid);
0003 %
0004 % Executes a command in the UNIX shell and returns results
0005 %
0006 %  unix_str - command to be executed
0007 %  nout - The expected number of output arguments 1=return status only
0008 %  errmsg - The string to be displayed if the command fails.
0009 %  logfid - The file ID where the command should be echoed. Default is stdout.
0010 
0011 % 03/22/06 Petr Janata
0012 
0013 if nargin < 4
0014   logfid = 1;
0015 end
0016 
0017 if nargin < 3
0018   errmsg = '';
0019 end
0020 
0021 if nargin < 2;
0022   nout = 1;
0023 end
0024 
0025 fprintf(logfid,'%s\n', unix_str);  % Echo the command
0026 [retval{1:nout}] = unix(unix_str);
0027 
0028 status = retval{1};
0029 if status
0030   error(errmsg)
0031 end
0032 
0033 for iout = 2:nout
0034   varargout{iout-1} = retval{iout};
0035 end
0036 
0037 return

Generated on Sat 24-Aug-2019 04:00:39 by m2html © 2003