comparison scripts/miscellaneous/unix.m @ 14018:5d5685216876

Deprecate shell_cmd function and update system, dos, unix commands * NEWS: Announce deprecation of shell_cmd. * deprecated/shell_cmd.m: New file to hold documentation and warning for shell_cmd. * deprecated/module.mk: Add shell_cmd to build system. * mk_undocumented_list: Remove shell_cmd from undocumented list. * install.txi: Replace reference to shell_cmd with system. * dos.m, unix.m: Update docstrings and add %!test block. * toplev.cc (system): Update docstring and add %!test block.
author Rik <octave@nomad.inbox5.com>
date Thu, 08 Dec 2011 17:25:30 -0800
parents fd0a3ac60b0e
children 72c96de7a403
comparison
equal deleted inserted replaced
14017:0b94080d2b0f 14018:5d5685216876
15 ## You should have received a copy of the GNU General Public License 15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see 16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>. 17 ## <http://www.gnu.org/licenses/>.
18 18
19 ## -*- texinfo -*- 19 ## -*- texinfo -*-
20 ## @deftypefn {Function File} {[@var{status}, @var{text}] =} unix (@var{command}) 20 ## @deftypefn {Function File} {} unix ("@var{command}")
21 ## @deftypefnx {Function File} {[@var{status}, @var{text}] =} unix (@var{command}, "-echo") 21 ## @deftypefnx {Function File} {@var{status} =} unix ("@var{command}")
22 ## @deftypefnx {Function File} {[@var{status}, @var{text}] =} unix ("@var{command}")
23 ## @deftypefnx {Function File} {[@dots{}] =} unix ("@var{command}", "-echo")
22 ## Execute a system command if running under a Unix-like operating 24 ## Execute a system command if running under a Unix-like operating
23 ## system, otherwise do nothing. Return the exit status of the program 25 ## system, otherwise do nothing. Return the exit status of the program
24 ## in @var{status} and any output sent to the standard output in 26 ## in @var{status} and any output from the command in @var{text}.
25 ## @var{text}. If the optional second argument @code{"-echo"} is given, 27 ## When called with no output argument, or the "-echo" argument is
26 ## then also send the output from the command to the standard output. 28 ## given, then @var{text} is also sent to standard output.
27 ## @seealso{isunix, ispc, system} 29 ## @seealso{dos, system, isunix, ispc}
28 ## @end deftypefn 30 ## @end deftypefn
29 31
30 ## Author: octave-forge ??? 32 ## Author: octave-forge ???
31 ## Adapted by: jwe 33 ## Adapted by: jwe
32 34
40 printf ("%s\n", text); 42 printf ("%s\n", text);
41 endif 43 endif
42 endif 44 endif
43 45
44 endfunction 46 endfunction
47
48
49 %!test
50 %! cmd = ls_command ();
51 %! old_wstate = warning ("query");
52 %! warning ("off", "Octave:undefined-return-values");
53 %! unwind_protect
54 %! [status, output] = unix (cmd);
55 %! unwind_protect_cleanup
56 %! warning (old_wstate);
57 %! end_unwind_protect
58 %!
59 %! if (isunix ())
60 %! assert (status, 0);
61 %! assert (ischar (output));
62 %! assert (! isempty (output));
63 %! else
64 %! assert (status, []);
65 %! assert (output, []);
66 %! endif
67
68 %!error unix ()
69 %!error unix (1, 2, 3)
70