comparison scripts/miscellaneous/python.m @ 13163:2ca9730d35ba

python: new function to invoke python scripts from octave code
author Carnë Draug <carandraug+dev@gmail.com>
date Mon, 19 Sep 2011 22:52:47 +0100
parents
children 6d59b141e65d
comparison
equal deleted inserted replaced
13162:4e92b71dcc97 13163:2ca9730d35ba
1 ## Copyright (C) 2008-2011 Julian Schnidder
2 ## Copyright (C) 2011 Carnë Draug <carandraug+dev@gmail.com>
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 function [output, status] = python (scriptfile = "-c ''", varargin)
31
32 ## VARARGIN is intialized to {}(1x0) if no additional arguments are
33 ## supplied, so there is no need to check for it, or provide an
34 ## initial value in the argument list of the function definition.
35
36 if (ischar (scriptfile)
37 && ((nargin != 1 && iscellstr (varargin))
38 || (nargin == 1 && ! isempty (scriptfile))))
39 [status, output] = system (cstrcat ("python ", scriptfile,
40 sprintf (" %s", varargin{:})));
41 else
42 error ("python: invalid arguments");
43 endif
44
45 endfunction