annotate scripts/pkg/private/shell.m @ 17535:c12c688a35ed default tip lyh

Fix warnings
author LYH <lyh.kernel@gmail.com>
date Fri, 27 Sep 2013 17:43:27 +0800
parents 1c89599167a6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14473
a46b8b0bd325 doc: Fix the encoding in Søren's name
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14466
diff changeset
1 ## Copyright (C) 2005-2012 Søren Hauberg
14466
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
2 ## Copyright (C) 2010 VZLU Prague, a.s.
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
3 ##
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
4 ## This file is part of Octave.
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
5 ##
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
6 ## Octave is free software; you can redistribute it and/or modify it
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
7 ## under the terms of the GNU General Public License as published by
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
8 ## the Free Software Foundation; either version 3 of the License, or (at
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
9 ## your option) any later version.
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
10 ##
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
11 ## Octave is distributed in the hope that it will be useful, but
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
14 ## General Public License for more details.
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
15 ##
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
16 ## You should have received a copy of the GNU General Public License
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
17 ## along with Octave; see the file COPYING. If not, see
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
18 ## <http://www.gnu.org/licenses/>.
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
19
16824
51bcaa55f120 pkg: display output of shell commands on real time if verbose.
Carnë Draug <carandraug+dev@gmail.com>
parents: 14868
diff changeset
20 ## Executes a shell command. In the end it calls system() but in case of
51bcaa55f120 pkg: display output of shell commands on real time if verbose.
Carnë Draug <carandraug+dev@gmail.com>
parents: 14868
diff changeset
21 ## windows will first check if sh.exe works.
51bcaa55f120 pkg: display output of shell commands on real time if verbose.
Carnë Draug <carandraug+dev@gmail.com>
parents: 14868
diff changeset
22 ##
51bcaa55f120 pkg: display output of shell commands on real time if verbose.
Carnë Draug <carandraug+dev@gmail.com>
parents: 14868
diff changeset
23 ## If VERBOSE is true, it will prints the output to STDOUT in real time and
51bcaa55f120 pkg: display output of shell commands on real time if verbose.
Carnë Draug <carandraug+dev@gmail.com>
parents: 14868
diff changeset
24 ## the second output argument will be an empty string. Otherwise, it will
51bcaa55f120 pkg: display output of shell commands on real time if verbose.
Carnë Draug <carandraug+dev@gmail.com>
parents: 14868
diff changeset
25 ## contain the output of the execeuted command.
14466
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
26
16824
51bcaa55f120 pkg: display output of shell commands on real time if verbose.
Carnë Draug <carandraug+dev@gmail.com>
parents: 14868
diff changeset
27 function [status, output] = shell (cmd, verbose)
14466
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
28 persistent have_sh;
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
29
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
30 cmd = strrep (cmd, "\\", "/");
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
31 if (ispc () && ! isunix ())
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14479
diff changeset
32 if (isempty (have_sh))
16994
333243133364 Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents: 16824
diff changeset
33 if (system ('sh.exe -c "exit"'))
14466
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
34 have_sh = false;
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
35 else
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
36 have_sh = true;
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
37 endif
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
38 endif
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
39 if (have_sh)
16994
333243133364 Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents: 16824
diff changeset
40 cmd = ['sh.exe -c "' cmd '"'];
14466
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
41 else
16824
51bcaa55f120 pkg: display output of shell commands on real time if verbose.
Carnë Draug <carandraug+dev@gmail.com>
parents: 14868
diff changeset
42 error ("pkg: unable to find the command shell.");
14466
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
43 endif
16824
51bcaa55f120 pkg: display output of shell commands on real time if verbose.
Carnë Draug <carandraug+dev@gmail.com>
parents: 14868
diff changeset
44 endif
51bcaa55f120 pkg: display output of shell commands on real time if verbose.
Carnë Draug <carandraug+dev@gmail.com>
parents: 14868
diff changeset
45 ## if verbose, we want to display the output in real time. To do this, we
51bcaa55f120 pkg: display output of shell commands on real time if verbose.
Carnë Draug <carandraug+dev@gmail.com>
parents: 14868
diff changeset
46 ## must call system with 1 output argument. But then the variable `output'
51bcaa55f120 pkg: display output of shell commands on real time if verbose.
Carnë Draug <carandraug+dev@gmail.com>
parents: 14868
diff changeset
47 ## won't exist. So we initialize it empty. If an error does occur, and we
51bcaa55f120 pkg: display output of shell commands on real time if verbose.
Carnë Draug <carandraug+dev@gmail.com>
parents: 14868
diff changeset
48 ## are verbose we will return an empty string but it's all fine since
51bcaa55f120 pkg: display output of shell commands on real time if verbose.
Carnë Draug <carandraug+dev@gmail.com>
parents: 14868
diff changeset
49 ## the error message has already been displayed.
51bcaa55f120 pkg: display output of shell commands on real time if verbose.
Carnë Draug <carandraug+dev@gmail.com>
parents: 14868
diff changeset
50 output = "";
51bcaa55f120 pkg: display output of shell commands on real time if verbose.
Carnë Draug <carandraug+dev@gmail.com>
parents: 14868
diff changeset
51 if (verbose)
51bcaa55f120 pkg: display output of shell commands on real time if verbose.
Carnë Draug <carandraug+dev@gmail.com>
parents: 14868
diff changeset
52 [status] = system (cmd);
14466
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
53 else
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
54 [status, output] = system (cmd);
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
55 endif
cfb0173fe1ca maint: Refactor pkg.m and move subfunctions to private/ directory.
Carlo de Falco <kingcrimson@tiscali.it>
parents:
diff changeset
56 endfunction
17346
1c89599167a6 maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents: 16994
diff changeset
57