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