]> Creatis software - CreaPhase.git/blob - octave_packages/m/miscellaneous/python.m
update packages
[CreaPhase.git] / octave_packages / m / miscellaneous / python.m
1 ## Copyright (C) 2008-2012 Julian Schnidder
2 ## Copyright (C) 2012 CarnĂ« Draug
3 ##
4 ## This file is part of Octave.
5 ##
6 ## Octave is free software; you can redistribute it and/or modify it
7 ## under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation; either version 3 of the License, or (at
9 ## your option) any later version.
10 ##
11 ## Octave is distributed in the hope that it will be useful, but
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ## General Public License for more details.
15 ##
16 ## You should have received a copy of the GNU General Public License
17 ## along with Octave; see the file COPYING.  If not, see
18 ## <http://www.gnu.org/licenses/>.
19
20 ## -*- texinfo -*-
21 ## @deftypefn  {Function File} {[@var{output}, @var{status}] =} python (@var{scriptfile})
22 ## @deftypefnx {Function File} {[@var{output}, @var{status}] =} python (@var{scriptfile}, @var{argument1}, @var{argument2}, @dots{})
23 ## Invoke python script @var{scriptfile} with possibly a list of
24 ## command line arguments.
25 ## Returns output in @var{output} and status
26 ## in @var{status}.
27 ## @seealso{system}
28 ## @end deftypefn
29
30 ## Author: CarnĂ« Draug <carandraug+dev@gmail.com>
31
32 function [output, status] = python (scriptfile = "-c ''", varargin)
33
34   ## VARARGIN is intialized to {}(1x0) if no additional arguments are
35   ## supplied, so there is no need to check for it, or provide an
36   ## initial value in the argument list of the function definition.
37
38   if (ischar (scriptfile)
39       && ((nargin != 1 && iscellstr (varargin))
40           || (nargin == 1 && ! isempty (scriptfile))))
41     [status, output] = system (cstrcat ("python ", scriptfile,
42                                         sprintf (" %s", varargin{:})));
43   else
44     error ("python: invalid arguments");
45   endif
46
47 endfunction