comparison scripts/miscellaneous/python.m @ 14818:c6ae30f73946

Look for perl/python scripts in Octave load path (bug #36729) * perl.m, python.m: Look for scripts using file_in_loadpath. Update docstring for new behavior.
author Rik <octave@nomad.inbox5.com>
date Fri, 29 Jun 2012 08:45:54 -0700
parents 72c96de7a403
children 333243133364
comparison
equal deleted inserted replaced
14817:67897baaa05f 14818:c6ae30f73946
16 ## You should have received a copy of the GNU General Public License 16 ## You should have received a copy of the GNU General Public License
17 ## along with Octave; see the file COPYING. If not, see 17 ## along with Octave; see the file COPYING. If not, see
18 ## <http://www.gnu.org/licenses/>. 18 ## <http://www.gnu.org/licenses/>.
19 19
20 ## -*- texinfo -*- 20 ## -*- texinfo -*-
21 ## @deftypefn {Function File} {[@var{output}, @var{status}] =} python (@var{scriptfile}) 21 ## @deftypefn {Function File} {@var{output} =} python (@var{scriptfile})
22 ## @deftypefnx {Function File} {[@var{output}, @var{status}] =} python (@var{scriptfile}, @var{argument1}, @var{argument2}, @dots{}) 22 ## @deftypefnx {Function File} {@var{output} =} python (@var{scriptfile}, @var{argument1}, @var{argument2}, @dots{})
23 ## Invoke python script @var{scriptfile} with possibly a list of 23 ## @deftypefnx {Function File} {[@var{output}, @var{status}] =} python (@dots{})
24 ## command line arguments. 24 ## Invoke Python script @var{scriptfile}, possibly with a list of command line
25 ## Returns output in @var{output} and status 25 ## arguments. Return output in @var{output} and optional status in
26 ## in @var{status}. 26 ## @var{status}. If @var{scriptfile} is not an absolute file name it is
27 ## @seealso{system} 27 ## is searched for in the current directory and then in the Octave loadpath.
28 ## @seealso{system, perl}
28 ## @end deftypefn 29 ## @end deftypefn
29 30
30 ## Author: Carnë Draug <carandraug+dev@gmail.com> 31 ## Author: Carnë Draug <carandraug+dev@gmail.com>
31 32
32 function [output, status] = python (scriptfile = "-c ''", varargin) 33 function [output, status] = python (scriptfile = "-c ''", varargin)
33 34
34 ## VARARGIN is intialized to {}(1x0) if no additional arguments are 35 if (ischar (scriptfile)
35 ## supplied, so there is no need to check for it, or provide an 36 && ( (nargin == 1 && ! isempty (scriptfile))
36 ## initial value in the argument list of the function definition. 37 || (nargin != 1 && iscellstr (varargin))))
38 if (! strcmp (scriptfile(1:2), "-c"))
39 ## Attempt to find file in loadpath. No effect for absolute filenames.
40 scriptfile = file_in_loadpath (scriptfile);
41 endif
37 42
38 if (ischar (scriptfile)
39 && ((nargin != 1 && iscellstr (varargin))
40 || (nargin == 1 && ! isempty (scriptfile))))
41 [status, output] = system (cstrcat ("python ", scriptfile, 43 [status, output] = system (cstrcat ("python ", scriptfile,
42 sprintf (" %s", varargin{:}))); 44 sprintf (" %s", varargin{:})));
43 else 45 else
44 error ("python: invalid arguments"); 46 error ("python: invalid arguments");
45 endif 47 endif