Mercurial > hg > octave-nkf
diff scripts/pkg/private/shell.m @ 16824:51bcaa55f120
pkg: display output of shell commands on real time if verbose.
* pkg/private/shell.m: display output of commands in real time and return
empty string when verbose. Also small refactor: create the 'special'
command for windows on its condition block rather than calling system()
there to reduce code duplication.
* pkg/private/configure_make.m: adjust call to shell() in order to display
output of `configure' and `make' on real time if verbose.
author | Carnë Draug <carandraug+dev@gmail.com> |
---|---|
date | Sun, 23 Jun 2013 13:25:26 +0100 |
parents | 5d3a684236b0 |
children | 333243133364 |
line wrap: on
line diff
--- a/scripts/pkg/private/shell.m +++ b/scripts/pkg/private/shell.m @@ -17,12 +17,14 @@ ## along with Octave; see the file COPYING. If not, see ## <http://www.gnu.org/licenses/>. -## -*- texinfo -*- -## @deftypefn {Function File} {[@var{status}, @var{output}] =} shell (@var{cmd}) -## Undocumented internal function. -## @end deftypefn +## Executes a shell command. In the end it calls system() but in case of +## windows will first check if sh.exe works. +## +## If VERBOSE is true, it will prints the output to STDOUT in real time and +## the second output argument will be an empty string. Otherwise, it will +## contain the output of the execeuted command. -function [status, output] = shell (cmd) +function [status, output] = shell (cmd, verbose) persistent have_sh; cmd = strrep (cmd, "\\", "/"); @@ -35,12 +37,20 @@ endif endif if (have_sh) - [status, output] = system (cstrcat ("sh.exe -c \"", cmd, "\"")); + cmd = cstrcat ("sh.exe -c \"", cmd, "\""); else - error ("Can not find the command shell"); + error ("pkg: unable to find the command shell."); endif + endif + ## if verbose, we want to display the output in real time. To do this, we + ## must call system with 1 output argument. But then the variable `output' + ## won't exist. So we initialize it empty. If an error does occur, and we + ## are verbose we will return an empty string but it's all fine since + ## the error message has already been displayed. + output = ""; + if (verbose) + [status] = system (cmd); else [status, output] = system (cmd); endif endfunction -