7018
|
1 @c Copyright (C) 1996, 1997, 1999, 2000, 2002, 2007 John W. Eaton |
|
2 @c |
|
3 @c This file is part of Octave. |
|
4 @c |
|
5 @c Octave is free software; you can redistribute it and/or modify it |
|
6 @c under the terms of the GNU General Public License as published by the |
|
7 @c Free Software Foundation; either version 3 of the License, or (at |
|
8 @c your option) any later version. |
|
9 @c |
|
10 @c Octave is distributed in the hope that it will be useful, but WITHOUT |
|
11 @c ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 @c FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 @c for more details. |
|
14 @c |
|
15 @c You should have received a copy of the GNU General Public License |
|
16 @c along with Octave; see the file COPYING. If not, see |
|
17 @c <http://www.gnu.org/licenses/>. |
3294
|
18 |
4167
|
19 @node System Utilities |
3294
|
20 @chapter System Utilities |
|
21 |
|
22 This chapter describes the functions that are available to allow you to |
|
23 get information about what is happening outside of Octave, while it is |
|
24 still running, and use this information in your program. For example, |
|
25 you can get information about environment variables, the current time, |
|
26 and even start other programs from the Octave prompt. |
|
27 |
|
28 @menu |
|
29 * Timing Utilities:: |
|
30 * Filesystem Utilities:: |
6549
|
31 * File Archiving Utilities:: |
|
32 * Networking Utilities:: |
3294
|
33 * Controlling Subprocesses:: |
|
34 * Process ID Information:: |
|
35 * Environment Variables:: |
|
36 * Current Working Directory:: |
|
37 * Password Database Functions:: |
|
38 * Group Database Functions:: |
|
39 * System Information:: |
6702
|
40 * Hashing Functions:: |
3294
|
41 @end menu |
|
42 |
4167
|
43 @node Timing Utilities |
3294
|
44 @section Timing Utilities |
|
45 |
|
46 Octave's core set of functions for manipulating time values are |
|
47 patterned after the corresponding functions from the standard C library. |
|
48 Several of these functions use a data structure for time that includes |
|
49 the following elements: |
|
50 |
|
51 @table @code |
|
52 @item usec |
|
53 Microseconds after the second (0-999999). |
|
54 |
|
55 @item sec |
|
56 Seconds after the minute (0-61). This number can be 61 to account |
|
57 for leap seconds. |
|
58 |
|
59 @item min |
|
60 Minutes after the hour (0-59). |
|
61 |
|
62 @item hour |
|
63 Hours since midnight (0-23). |
|
64 |
|
65 @item mday |
|
66 Day of the month (1-31). |
|
67 |
|
68 @item mon |
|
69 Months since January (0-11). |
|
70 |
|
71 @item year |
|
72 Years since 1900. |
|
73 |
|
74 @item wday |
|
75 Days since Sunday (0-6). |
|
76 |
|
77 @item yday |
|
78 Days since January 1 (0-365). |
|
79 |
|
80 @item isdst |
|
81 Daylight Savings Time flag. |
|
82 |
|
83 @item zone |
|
84 Time zone. |
|
85 @end table |
|
86 |
|
87 @noindent |
|
88 In the descriptions of the following functions, this structure is |
|
89 referred to as a @var{tm_struct}. |
|
90 |
3301
|
91 @DOCSTRING(time) |
3294
|
92 |
6502
|
93 @DOCSTRING(now) |
|
94 |
3294
|
95 @DOCSTRING(ctime) |
|
96 |
3301
|
97 @DOCSTRING(gmtime) |
3294
|
98 |
3301
|
99 @DOCSTRING(localtime) |
3294
|
100 |
3301
|
101 @DOCSTRING(mktime) |
3294
|
102 |
3301
|
103 @DOCSTRING(asctime) |
3294
|
104 |
|
105 @DOCSTRING(strftime) |
|
106 |
4169
|
107 @DOCSTRING(strptime) |
|
108 |
3294
|
109 Most of the remaining functions described in this section are not |
|
110 patterned after the standard C library. Some are available for |
6939
|
111 compatibility with @sc{Matlab} and others are provided because they are |
3294
|
112 useful. |
|
113 |
3301
|
114 @DOCSTRING(clock) |
3294
|
115 |
3301
|
116 @DOCSTRING(date) |
3294
|
117 |
3301
|
118 @DOCSTRING(etime) |
3294
|
119 |
3301
|
120 @DOCSTRING(cputime) |
3294
|
121 |
3301
|
122 @DOCSTRING(is_leap_year) |
3294
|
123 |
3301
|
124 @DOCSTRING(tic) |
3294
|
125 |
3301
|
126 @DOCSTRING(pause) |
3294
|
127 |
3301
|
128 @DOCSTRING(sleep) |
3294
|
129 |
3301
|
130 @DOCSTRING(usleep) |
3294
|
131 |
6502
|
132 @DOCSTRING( datenum) |
|
133 |
|
134 @DOCSTRING(datestr) |
|
135 |
|
136 @DOCSTRING(datevec) |
|
137 |
|
138 @DOCSTRING(calendar) |
|
139 |
|
140 @DOCSTRING(weekday) |
|
141 |
|
142 @DOCSTRING(eomday) |
|
143 |
4167
|
144 @node Filesystem Utilities |
3294
|
145 @section Filesystem Utilities |
|
146 |
|
147 Octave includes the following functions for renaming and deleting files, |
|
148 creating, deleting, and reading directories, and for getting information |
|
149 about the status of files. |
|
150 |
3301
|
151 @DOCSTRING(rename) |
3294
|
152 |
3710
|
153 @DOCSTRING(link) |
|
154 |
|
155 @DOCSTRING(symlink) |
|
156 |
4169
|
157 @DOCSTRING(readlink) |
|
158 |
3301
|
159 @DOCSTRING(unlink) |
3294
|
160 |
3301
|
161 @DOCSTRING(readdir) |
3294
|
162 |
3301
|
163 @DOCSTRING(mkdir) |
3294
|
164 |
3301
|
165 @DOCSTRING(rmdir) |
3294
|
166 |
6550
|
167 @DOCSTRING(confirm_recursive_rmdir) |
|
168 |
3301
|
169 @DOCSTRING(mkfifo) |
3294
|
170 |
3301
|
171 @DOCSTRING(umask) |
3294
|
172 |
3301
|
173 @DOCSTRING(stat) |
3294
|
174 |
6549
|
175 @DOCSTRING(lstat) |
|
176 |
|
177 @DOCSTRING(fileattrib) |
|
178 |
|
179 @DOCSTRING(isdir) |
|
180 |
3301
|
181 @DOCSTRING(glob) |
3294
|
182 |
3428
|
183 @DOCSTRING(fnmatch) |
|
184 |
3301
|
185 @DOCSTRING(file_in_path) |
3294
|
186 |
3301
|
187 @DOCSTRING(tilde_expand) |
3294
|
188 |
6549
|
189 @DOCSTRING(canonicalize_file_name) |
|
190 |
|
191 @DOCSTRING(movefile) |
|
192 |
|
193 @DOCSTRING(copyfile) |
|
194 |
|
195 @DOCSTRING(fileparts) |
|
196 |
|
197 @DOCSTRING(filesep) |
|
198 |
|
199 @DOCSTRING(fullfile) |
|
200 |
|
201 @DOCSTRING(tempdir) |
|
202 |
|
203 @DOCSTRING(tempname) |
|
204 |
|
205 @DOCSTRING(P_tmpdir) |
|
206 |
|
207 @node File Archiving Utilities |
|
208 @section File Archiving Utilities |
|
209 |
|
210 @DOCSTRING(bunzip2) |
|
211 |
6868
|
212 @DOCSTRING(gzip) |
|
213 |
6549
|
214 @DOCSTRING(gunzip) |
|
215 |
|
216 @DOCSTRING(tar) |
|
217 |
|
218 @DOCSTRING(untar) |
|
219 |
|
220 @DOCSTRING(zip) |
|
221 |
|
222 @DOCSTRING(unzip) |
|
223 |
|
224 @DOCSTRING(pack) |
|
225 |
|
226 @DOCSTRING(unpack) |
|
227 |
|
228 @node Networking Utilities |
|
229 @section Networking Utilities |
|
230 |
|
231 @DOCSTRING(urlread) |
|
232 |
|
233 @DOCSTRING(urlwrite) |
|
234 |
4167
|
235 @node Controlling Subprocesses |
3294
|
236 @section Controlling Subprocesses |
|
237 |
|
238 Octave includes some high-level commands like @code{system} and |
|
239 @code{popen} for starting subprocesses. If you want to run another |
|
240 program to perform some task and then look at its output, you will |
|
241 probably want to use these functions. |
|
242 |
|
243 Octave also provides several very low-level Unix-like functions which |
|
244 can also be used for starting subprocesses, but you should probably only |
|
245 use them if you can't find any way to do what you need with the |
|
246 higher-level functions. |
|
247 |
3301
|
248 @DOCSTRING(system) |
3294
|
249 |
6549
|
250 @DOCSTRING(unix) |
|
251 |
|
252 @DOCSTRING(dos) |
|
253 |
3301
|
254 @DOCSTRING(popen) |
3294
|
255 |
3301
|
256 @DOCSTRING(pclose) |
3294
|
257 |
3301
|
258 @DOCSTRING(popen2) |
3294
|
259 |
3301
|
260 @DOCSTRING(EXEC_PATH) |
3294
|
261 |
|
262 In most cases, the following functions simply decode their arguments and |
|
263 make the corresponding Unix system calls. For a complete example of how |
|
264 they can be used, look at the definition of the function @code{popen2}. |
|
265 |
3301
|
266 @DOCSTRING(fork) |
3294
|
267 |
3301
|
268 @DOCSTRING(exec) |
3294
|
269 |
3301
|
270 @DOCSTRING(pipe) |
3294
|
271 |
3301
|
272 @DOCSTRING(dup2) |
3294
|
273 |
3301
|
274 @DOCSTRING(waitpid) |
3294
|
275 |
3301
|
276 @DOCSTRING(fcntl) |
3294
|
277 |
6549
|
278 @DOCSTRING(kill) |
|
279 |
|
280 @DOCSTRING(SIG) |
|
281 |
4167
|
282 @node Process ID Information |
3294
|
283 @section Process, Group, and User IDs |
|
284 |
3301
|
285 @DOCSTRING(getpgrp) |
3294
|
286 |
3301
|
287 @DOCSTRING(getpid) |
3294
|
288 |
3301
|
289 @DOCSTRING(getppid) |
3294
|
290 |
3301
|
291 @DOCSTRING(geteuid) |
3294
|
292 |
3301
|
293 @DOCSTRING(getuid) |
3294
|
294 |
3301
|
295 @DOCSTRING(getegid) |
3294
|
296 |
3301
|
297 @DOCSTRING(getgid) |
3294
|
298 |
4167
|
299 @node Environment Variables |
3294
|
300 @section Environment Variables |
|
301 |
3301
|
302 @DOCSTRING(getenv) |
3294
|
303 |
3301
|
304 @DOCSTRING(putenv) |
3294
|
305 |
4167
|
306 @node Current Working Directory |
3294
|
307 @section Current Working Directory |
|
308 |
3301
|
309 @DOCSTRING(cd) |
3294
|
310 |
3301
|
311 @DOCSTRING(ls) |
3294
|
312 |
6549
|
313 @DOCSTRING(ls_command) |
|
314 |
|
315 @DOCSTRING(dir) |
|
316 |
3301
|
317 @DOCSTRING(pwd) |
3294
|
318 |
4167
|
319 @node Password Database Functions |
3294
|
320 @section Password Database Functions |
|
321 |
|
322 Octave's password database functions return information in a structure |
|
323 with the following fields. |
|
324 |
|
325 @table @code |
|
326 @item name |
|
327 The user name. |
|
328 |
|
329 @item passwd |
|
330 The encrypted password, if available. |
|
331 |
|
332 @item uid |
|
333 The numeric user id. |
|
334 |
|
335 @item gid |
|
336 The numeric group id. |
|
337 |
|
338 @item gecos |
|
339 The GECOS field. |
|
340 |
|
341 @item dir |
|
342 The home directory. |
|
343 |
|
344 @item shell |
|
345 The initial shell. |
|
346 @end table |
|
347 |
|
348 In the descriptions of the following functions, this data structure is |
|
349 referred to as a @var{pw_struct}. |
|
350 |
3301
|
351 @DOCSTRING(getpwent) |
3294
|
352 |
3301
|
353 @DOCSTRING(getpwuid) |
3294
|
354 |
3301
|
355 @DOCSTRING(getpwnam) |
3294
|
356 |
3301
|
357 @DOCSTRING(setpwent) |
3294
|
358 |
3301
|
359 @DOCSTRING(endpwent) |
3294
|
360 |
4167
|
361 @node Group Database Functions |
3294
|
362 @section Group Database Functions |
|
363 |
|
364 Octave's group database functions return information in a structure |
|
365 with the following fields. |
|
366 |
|
367 @table @code |
|
368 @item name |
|
369 The user name. |
|
370 |
|
371 @item passwd |
|
372 The encrypted password, if available. |
|
373 |
|
374 @item gid |
|
375 The numeric group id. |
|
376 |
|
377 @item mem |
|
378 The members of the group. |
|
379 @end table |
|
380 |
|
381 In the descriptions of the following functions, this data structure is |
|
382 referred to as a @var{grp_struct}. |
|
383 |
3301
|
384 @DOCSTRING(getgrent) |
3294
|
385 |
3301
|
386 @DOCSTRING(getgrgid) |
|
387 |
|
388 @DOCSTRING(getgrnam) |
3294
|
389 |
3301
|
390 @DOCSTRING(setgrent) |
3294
|
391 |
3301
|
392 @DOCSTRING(endgrent) |
3294
|
393 |
4167
|
394 @node System Information |
3294
|
395 @section System Information |
|
396 |
3301
|
397 @DOCSTRING(computer) |
3294
|
398 |
6549
|
399 @DOCSTRING(uname) |
|
400 |
|
401 @DOCSTRING(ispc) |
|
402 |
|
403 @DOCSTRING(isunix) |
|
404 |
3301
|
405 @DOCSTRING(isieee) |
3294
|
406 |
6623
|
407 @DOCSTRING(OCTAVE_HOME) |
|
408 |
3301
|
409 @DOCSTRING(OCTAVE_VERSION) |
3294
|
410 |
6623
|
411 @DOCSTRING(version) |
|
412 |
|
413 @DOCSTRING(ver) |
|
414 |
3301
|
415 @DOCSTRING(octave_config_info) |
3294
|
416 |
3301
|
417 @DOCSTRING(getrusage) |
6702
|
418 |
|
419 @node Hashing Functions |
|
420 @section Hashing Functions |
|
421 |
|
422 It is often necessary to find if two strings or files are |
|
423 identical. This might be done by comparing them character by character |
|
424 and looking for differences. However, this can be slow, and so comparing |
|
425 a hash of the string or file can be a rapid way of finding if the files |
|
426 differ. |
|
427 |
|
428 Another use of the hashing function is to check for file integrity. The |
|
429 user can check the hash of the file against a known value and find if |
|
430 the file they have is the same as the one that the original hash was |
|
431 produced with. |
|
432 |
7007
|
433 Octave supplies the @code{md5sum} function to perform MD5 hashes on |
6702
|
434 strings and files. An example of the use of @code{md5sum} function might |
|
435 be |
|
436 |
|
437 @example |
|
438 @group |
|
439 if exist (file, "file") |
|
440 hash = md5sum (file); |
|
441 else |
|
442 # Treat the variable "file" as a string |
|
443 hash = md5sum (file, true); |
|
444 endif |
|
445 @end group |
|
446 @end example |
|
447 |
|
448 @DOCSTRING(md5sum) |