blob: 51f00273eff037d3178873193801fdbcab735652 [file] [log] [blame]
Fred Drake295da241998-08-10 19:42:37 +00001\section{\module{os} ---
Fred Drake8ee679f2001-07-14 02:50:55 +00002 Miscellaneous operating system interfaces}
Fred Drakeb91e9341998-07-23 17:59:49 +00003
Fred Drakeec6baaf1999-04-21 18:13:31 +00004\declaremodule{standard}{os}
Fred Drake8ee679f2001-07-14 02:50:55 +00005\modulesynopsis{Miscellaneous operating system interfaces.}
Fred Drakeb91e9341998-07-23 17:59:49 +00006
Fred Drakec4f15af1998-03-10 03:17:26 +00007
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00008This module provides a more portable way of using operating system
Fred Drake8ee679f2001-07-14 02:50:55 +00009dependent functionality than importing a operating system dependent
10built-in module like \refmodule{posix} or \module{nt}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000011
Fred Drake8ee679f2001-07-14 02:50:55 +000012This module searches for an operating system dependent built-in module like
Fred Drake2f979011999-06-11 18:28:37 +000013\module{mac} or \refmodule{posix} and exports the same functions and data
Fred Drake8ee679f2001-07-14 02:50:55 +000014as found there. The design of all Python's built-in operating system dependent
Fred Drake215fe2f1999-02-02 19:02:35 +000015modules is such that as long as the same functionality is available,
Fred Drake907e76b2001-07-06 20:30:11 +000016it uses the same interface; for example, the function
Fred Drakeec6baaf1999-04-21 18:13:31 +000017\code{os.stat(\var{path})} returns stat information about \var{path} in
18the same format (which happens to have originated with the
19\POSIX{} interface).
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000020
Fred Drake8ee679f2001-07-14 02:50:55 +000021Extensions peculiar to a particular operating system are also
22available through the \module{os} module, but using them is of course a
23threat to portability!
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000024
Fred Drakec4f15af1998-03-10 03:17:26 +000025Note that after the first time \module{os} is imported, there is
26\emph{no} performance penalty in using functions from \module{os}
Fred Drake8ee679f2001-07-14 02:50:55 +000027instead of directly from the operating system dependent built-in module,
28so there should be \emph{no} reason not to use \module{os}!
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000029
Fred Drake215fe2f1999-02-02 19:02:35 +000030
Fred Drake859dc531999-07-01 13:54:40 +000031% Frank Stajano <fstajano@uk.research.att.com> complained that it
32% wasn't clear that the entries described in the subsections were all
33% available at the module level (most uses of subsections are
34% different); I think this is only a problem for the HTML version,
35% where the relationship may not be as clear.
36%
37\ifhtml
38The \module{os} module contains many functions and data values.
39The items below and in the following sub-sections are all available
40directly from the \module{os} module.
41\fi
42
43
Fred Drake215fe2f1999-02-02 19:02:35 +000044\begin{excdesc}{error}
Fred Drake907e76b2001-07-06 20:30:11 +000045This exception is raised when a function returns a system-related
46error (not for illegal argument types or other incidental errors).
47This is also known as the built-in exception \exception{OSError}. The
Fred Drake215fe2f1999-02-02 19:02:35 +000048accompanying value is a pair containing the numeric error code from
49\cdata{errno} and the corresponding string, as would be printed by the
50C function \cfunction{perror()}. See the module
51\refmodule{errno}\refbimodindex{errno}, which contains names for the
52error codes defined by the underlying operating system.
53
54When exceptions are classes, this exception carries two attributes,
55\member{errno} and \member{strerror}. The first holds the value of
56the C \cdata{errno} variable, and the latter holds the corresponding
57error message from \cfunction{strerror()}. For exceptions that
Fred Drake907e76b2001-07-06 20:30:11 +000058involve a file system path (such as \function{chdir()} or
Fred Drake215fe2f1999-02-02 19:02:35 +000059\function{unlink()}), the exception instance will contain a third
60attribute, \member{filename}, which is the file name passed to the
61function.
Fred Drake215fe2f1999-02-02 19:02:35 +000062\end{excdesc}
Guido van Rossum470be141995-03-17 16:07:09 +000063
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000064\begin{datadesc}{name}
Fred Drake8ee679f2001-07-14 02:50:55 +000065The name of the operating system dependent module imported. The
Fred Drake6995bb62001-11-29 20:48:44 +000066following names have currently been registered: \code{'posix'},
67\code{'nt'}, \code{'dos'}, \code{'mac'}, \code{'os2'}, \code{'ce'},
68\code{'java'}, \code{'riscos'}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000069\end{datadesc}
70
71\begin{datadesc}{path}
Fred Drake8ee679f2001-07-14 02:50:55 +000072The corresponding operating system dependent standard module for pathname
Fred Drake907e76b2001-07-06 20:30:11 +000073operations, such as \module{posixpath} or \module{macpath}. Thus,
74given the proper imports, \code{os.path.split(\var{file})} is
75equivalent to but more portable than
76\code{posixpath.split(\var{file})}. Note that this is also an
77importable module: it may be imported directly as
Fred Drake215fe2f1999-02-02 19:02:35 +000078\refmodule{os.path}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000079\end{datadesc}
80
Fred Drake215fe2f1999-02-02 19:02:35 +000081
82
83\subsection{Process Parameters \label{os-procinfo}}
84
85These functions and data items provide information and operate on the
86current process and user.
87
Fred Drake215fe2f1999-02-02 19:02:35 +000088\begin{datadesc}{environ}
Fred Drake0e1de8b1999-04-29 12:57:32 +000089A mapping object representing the string environment. For example,
90\code{environ['HOME']} is the pathname of your home directory (on some
91platforms), and is equivalent to \code{getenv("HOME")} in C.
Fred Drake215fe2f1999-02-02 19:02:35 +000092
93If the platform supports the \function{putenv()} function, this
94mapping may be used to modify the environment as well as query the
95environment. \function{putenv()} will be called automatically when
96the mapping is modified.
97
98If \function{putenv()} is not provided, this mapping may be passed to
99the appropriate process-creation functions to cause child processes to
100use a modified environment.
101\end{datadesc}
102
Fred Drake6db897c1999-07-12 16:49:30 +0000103\begin{funcdescni}{chdir}{path}
104\funclineni{getcwd}{}
105These functions are described in ``Files and Directories'' (section
106\ref{os-file-dir}).
107\end{funcdescni}
Fred Drake215fe2f1999-02-02 19:02:35 +0000108
Fred Drake18f7a451999-12-09 22:11:43 +0000109\begin{funcdesc}{ctermid}{}
110Return the filename corresponding to the controlling terminal of the
111process.
Fred Drakec37b65e2001-11-28 07:26:15 +0000112Availability: \UNIX.
Fred Drake18f7a451999-12-09 22:11:43 +0000113\end{funcdesc}
114
Fred Drake215fe2f1999-02-02 19:02:35 +0000115\begin{funcdesc}{getegid}{}
116Return the current process' effective group id.
Fred Drakec37b65e2001-11-28 07:26:15 +0000117Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000118\end{funcdesc}
119
120\begin{funcdesc}{geteuid}{}
Fred Drake6b330ba81999-05-25 13:42:26 +0000121\index{user!effective id}
Fred Drake215fe2f1999-02-02 19:02:35 +0000122Return the current process' effective user id.
Fred Drakec37b65e2001-11-28 07:26:15 +0000123Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000124\end{funcdesc}
125
126\begin{funcdesc}{getgid}{}
Fred Drake6b330ba81999-05-25 13:42:26 +0000127\index{process!group}
Fred Drake215fe2f1999-02-02 19:02:35 +0000128Return the current process' group id.
Fred Drakec37b65e2001-11-28 07:26:15 +0000129Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000130\end{funcdesc}
131
Fred Drake88f6ca21999-12-15 19:39:04 +0000132\begin{funcdesc}{getgroups}{}
133Return list of supplemental group ids associated with the current
134process.
Fred Drakec37b65e2001-11-28 07:26:15 +0000135Availability: \UNIX.
Fred Drake88f6ca21999-12-15 19:39:04 +0000136\end{funcdesc}
137
138\begin{funcdesc}{getlogin}{}
139Return the actual login name for the current process, even if there
140are multiple login names which map to the same user id.
Fred Drakec37b65e2001-11-28 07:26:15 +0000141Availability: \UNIX.
Fred Drake88f6ca21999-12-15 19:39:04 +0000142\end{funcdesc}
143
Fred Drake215fe2f1999-02-02 19:02:35 +0000144\begin{funcdesc}{getpgrp}{}
145\index{process!group}
146Return the current process group id.
Fred Drakec37b65e2001-11-28 07:26:15 +0000147Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000148\end{funcdesc}
149
150\begin{funcdesc}{getpid}{}
151\index{process!id}
152Return the current process id.
Fred Drakec37b65e2001-11-28 07:26:15 +0000153Availability: \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000154\end{funcdesc}
155
156\begin{funcdesc}{getppid}{}
157\index{process!id of parent}
158Return the parent's process id.
Fred Drakec37b65e2001-11-28 07:26:15 +0000159Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000160\end{funcdesc}
161
162\begin{funcdesc}{getuid}{}
Fred Drake6b330ba81999-05-25 13:42:26 +0000163\index{user!id}
Fred Drake215fe2f1999-02-02 19:02:35 +0000164Return the current process' user id.
Fred Drakec37b65e2001-11-28 07:26:15 +0000165Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000166\end{funcdesc}
167
Fred Drake81e142b2001-05-31 20:27:46 +0000168\begin{funcdesc}{getenv}{varname\optional{, value}}
169Return the value of the environment variable \var{varname} if it
170exists, or \var{value} if it doesn't. \var{value} defaults to
171\code{None}.
Fred Drakec37b65e2001-11-28 07:26:15 +0000172Availability: most flavors of \UNIX, Windows.
Fred Drake81e142b2001-05-31 20:27:46 +0000173\end{funcdesc}
174
Fred Drake215fe2f1999-02-02 19:02:35 +0000175\begin{funcdesc}{putenv}{varname, value}
176\index{environment variables!setting}
177Set the environment variable named \var{varname} to the string
178\var{value}. Such changes to the environment affect subprocesses
179started with \function{os.system()}, \function{popen()} or
180\function{fork()} and \function{execv()}.
Fred Drakec37b65e2001-11-28 07:26:15 +0000181Availability: most flavors of \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000182
183When \function{putenv()} is
184supported, assignments to items in \code{os.environ} are automatically
185translated into corresponding calls to \function{putenv()}; however,
186calls to \function{putenv()} don't update \code{os.environ}, so it is
187actually preferable to assign to items of \code{os.environ}.
188\end{funcdesc}
189
Andrew M. Kuchling8d2f2b22000-07-13 01:26:58 +0000190\begin{funcdesc}{setegid}{egid}
191Set the current process's effective group id.
Fred Drakec37b65e2001-11-28 07:26:15 +0000192Availability: \UNIX.
Andrew M. Kuchling8d2f2b22000-07-13 01:26:58 +0000193\end{funcdesc}
194
195\begin{funcdesc}{seteuid}{euid}
196Set the current process's effective user id.
Fred Drakec37b65e2001-11-28 07:26:15 +0000197Availability: \UNIX.
Andrew M. Kuchling8d2f2b22000-07-13 01:26:58 +0000198\end{funcdesc}
199
Fred Drake215fe2f1999-02-02 19:02:35 +0000200\begin{funcdesc}{setgid}{gid}
201Set the current process' group id.
Fred Drakec37b65e2001-11-28 07:26:15 +0000202Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000203\end{funcdesc}
204
Martin v. Löwis61c5edf2001-10-18 04:06:00 +0000205\begin{funcdesc}{setgroups}{groups}
Martin v. Löwisc4051332001-10-18 14:07:12 +0000206Set the list of supplemental group ids associated with the current
207process to \var{groups}. \var{groups} must be a sequence, and each
208element must be an integer identifying a group. This operation is
209typical available only to the superuser.
Fred Drakec37b65e2001-11-28 07:26:15 +0000210Availability: \UNIX.
Martin v. Löwis61c5edf2001-10-18 04:06:00 +0000211\versionadded{2.2}
212\end{funcdesc}
213
Fred Drake215fe2f1999-02-02 19:02:35 +0000214\begin{funcdesc}{setpgrp}{}
215Calls the system call \cfunction{setpgrp()} or \cfunction{setpgrp(0,
2160)} depending on which version is implemented (if any). See the
217\UNIX{} manual for the semantics.
Fred Drakec37b65e2001-11-28 07:26:15 +0000218Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000219\end{funcdesc}
220
221\begin{funcdesc}{setpgid}{pid, pgrp}
222Calls the system call \cfunction{setpgid()}. See the \UNIX{} manual
223for the semantics.
Fred Drakec37b65e2001-11-28 07:26:15 +0000224Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000225\end{funcdesc}
226
Andrew M. Kuchling8d2f2b22000-07-13 01:26:58 +0000227\begin{funcdesc}{setreuid}{ruid, euid}
228Set the current process's real and effective user ids.
Fred Drakec37b65e2001-11-28 07:26:15 +0000229Availability: \UNIX.
Andrew M. Kuchling8d2f2b22000-07-13 01:26:58 +0000230\end{funcdesc}
231
232\begin{funcdesc}{setregid}{rgid, egid}
233Set the current process's real and effective group ids.
Fred Drakec37b65e2001-11-28 07:26:15 +0000234Availability: \UNIX.
Andrew M. Kuchling8d2f2b22000-07-13 01:26:58 +0000235\end{funcdesc}
236
Fred Drake215fe2f1999-02-02 19:02:35 +0000237\begin{funcdesc}{setsid}{}
238Calls the system call \cfunction{setsid()}. See the \UNIX{} manual
239for the semantics.
Fred Drakec37b65e2001-11-28 07:26:15 +0000240Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000241\end{funcdesc}
242
243\begin{funcdesc}{setuid}{uid}
Fred Drake6b330ba81999-05-25 13:42:26 +0000244\index{user!id, setting}
Fred Drake215fe2f1999-02-02 19:02:35 +0000245Set the current process' user id.
Fred Drakec37b65e2001-11-28 07:26:15 +0000246Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000247\end{funcdesc}
248
249% placed in this section since it relates to errno.... a little weak ;-(
250\begin{funcdesc}{strerror}{code}
251Return the error message corresponding to the error code in
252\var{code}.
Fred Drakec37b65e2001-11-28 07:26:15 +0000253Availability: \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000254\end{funcdesc}
255
256\begin{funcdesc}{umask}{mask}
257Set the current numeric umask and returns the previous umask.
Fred Drakec37b65e2001-11-28 07:26:15 +0000258Availability: \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000259\end{funcdesc}
260
261\begin{funcdesc}{uname}{}
262Return a 5-tuple containing information identifying the current
263operating system. The tuple contains 5 strings:
264\code{(\var{sysname}, \var{nodename}, \var{release}, \var{version},
265\var{machine})}. Some systems truncate the nodename to 8
266characters or to the leading component; a better way to get the
267hostname is \function{socket.gethostname()}
268\withsubitem{(in module socket)}{\ttindex{gethostname()}}
269or even
270\withsubitem{(in module socket)}{\ttindex{gethostbyaddr()}}
271\code{socket.gethostbyaddr(socket.gethostname())}.
Fred Drakec37b65e2001-11-28 07:26:15 +0000272Availability: recent flavors of \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000273\end{funcdesc}
274
275
276
277\subsection{File Object Creation \label{os-newstreams}}
278
279These functions create new file objects.
280
281
282\begin{funcdesc}{fdopen}{fd\optional{, mode\optional{, bufsize}}}
283Return an open file object connected to the file descriptor \var{fd}.
Fred Drake8c9fc001999-08-05 13:41:31 +0000284\index{I/O control!buffering}
Fred Drake215fe2f1999-02-02 19:02:35 +0000285The \var{mode} and \var{bufsize} arguments have the same meaning as
286the corresponding arguments to the built-in \function{open()}
287function.
Fred Drakec37b65e2001-11-28 07:26:15 +0000288Availability: Macintosh, \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000289\end{funcdesc}
290
291\begin{funcdesc}{popen}{command\optional{, mode\optional{, bufsize}}}
292Open a pipe to or from \var{command}. The return value is an open
293file object connected to the pipe, which can be read or written
294depending on whether \var{mode} is \code{'r'} (default) or \code{'w'}.
295The \var{bufsize} argument has the same meaning as the corresponding
296argument to the built-in \function{open()} function. The exit status of
297the command (encoded in the format specified for \function{wait()}) is
298available as the return value of the \method{close()} method of the file
299object, except that when the exit status is zero (termination without
Fred Drake1319e3e2000-10-03 17:14:27 +0000300errors), \code{None} is returned.
Fred Drakec37b65e2001-11-28 07:26:15 +0000301Availability: \UNIX, Windows.
Fred Drakec71c23e2000-10-04 13:57:27 +0000302
303\versionchanged[This function worked unreliably under Windows in
304 earlier versions of Python. This was due to the use of the
305 \cfunction{_popen()} function from the libraries provided with
306 Windows. Newer versions of Python do not use the broken
307 implementation from the Windows libraries]{2.0}
Fred Drake215fe2f1999-02-02 19:02:35 +0000308\end{funcdesc}
309
Fred Drake18f7a451999-12-09 22:11:43 +0000310\begin{funcdesc}{tmpfile}{}
311Return a new file object opened in update mode (\samp{w+}). The file
312has no directory entries associated with it and will be automatically
313deleted once there are no file descriptors for the file.
Fred Drakec37b65e2001-11-28 07:26:15 +0000314Availability: \UNIX, Windows.
Fred Drake18f7a451999-12-09 22:11:43 +0000315\end{funcdesc}
Fred Drake215fe2f1999-02-02 19:02:35 +0000316
317
Fred Drake8a9db992000-09-28 20:27:51 +0000318For each of these \function{popen()} variants, if \var{bufsize} is
319specified, it specifies the buffer size for the I/O pipes.
320\var{mode}, if provided, should be the string \code{'b'} or
321\code{'t'}; on Windows this is needed to determine whether the file
322objects should be opened in binary or text mode. The default value
323for \var{mode} is \code{'t'}.
324
Fred Drake098d7fa2001-09-11 19:56:51 +0000325These methods do not make it possible to retrieve the return code from
326the child processes. The only way to control the input and output
327streams and also retrieve the return codes is to use the
328\class{Popen3} and \class{Popen4} classes from the \refmodule{popen2}
329module; these are only available on \UNIX.
330
Fred Drake046f4d82001-06-11 15:21:48 +0000331\begin{funcdesc}{popen2}{cmd\optional{, mode\optional{, bufsize}}}
Fred Drake8a9db992000-09-28 20:27:51 +0000332Executes \var{cmd} as a sub-process. Returns the file objects
333\code{(\var{child_stdin}, \var{child_stdout})}.
Fred Drakec37b65e2001-11-28 07:26:15 +0000334Availability: \UNIX, Windows.
Fred Drake8a9db992000-09-28 20:27:51 +0000335\versionadded{2.0}
336\end{funcdesc}
337
Fred Drake046f4d82001-06-11 15:21:48 +0000338\begin{funcdesc}{popen3}{cmd\optional{, mode\optional{, bufsize}}}
Fred Drake8a9db992000-09-28 20:27:51 +0000339Executes \var{cmd} as a sub-process. Returns the file objects
340\code{(\var{child_stdin}, \var{child_stdout}, \var{child_stderr})}.
Fred Drakec37b65e2001-11-28 07:26:15 +0000341Availability: \UNIX, Windows.
Fred Drake8a9db992000-09-28 20:27:51 +0000342\versionadded{2.0}
343\end{funcdesc}
344
Fred Drake046f4d82001-06-11 15:21:48 +0000345\begin{funcdesc}{popen4}{cmd\optional{, mode\optional{, bufsize}}}
Fred Drake8a9db992000-09-28 20:27:51 +0000346Executes \var{cmd} as a sub-process. Returns the file objects
347\code{(\var{child_stdin}, \var{child_stdout_and_stderr})}.
Fred Drakec37b65e2001-11-28 07:26:15 +0000348Availability: \UNIX, Windows.
Fred Drake8a9db992000-09-28 20:27:51 +0000349\versionadded{2.0}
350\end{funcdesc}
351
352This functionality is also available in the \refmodule{popen2} module
353using functions of the same names, but the return values of those
354functions have a different order.
355
356
Fred Drake215fe2f1999-02-02 19:02:35 +0000357\subsection{File Descriptor Operations \label{os-fd-ops}}
358
359These functions operate on I/O streams referred to
360using file descriptors.
361
362
363\begin{funcdesc}{close}{fd}
364Close file descriptor \var{fd}.
Fred Drakec37b65e2001-11-28 07:26:15 +0000365Availability: Macintosh, \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000366
367Note: this function is intended for low-level I/O and must be applied
368to a file descriptor as returned by \function{open()} or
369\function{pipe()}. To close a ``file object'' returned by the
370built-in function \function{open()} or by \function{popen()} or
371\function{fdopen()}, use its \method{close()} method.
372\end{funcdesc}
373
374\begin{funcdesc}{dup}{fd}
375Return a duplicate of file descriptor \var{fd}.
Fred Drakec37b65e2001-11-28 07:26:15 +0000376Availability: Macintosh, \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000377\end{funcdesc}
378
379\begin{funcdesc}{dup2}{fd, fd2}
380Duplicate file descriptor \var{fd} to \var{fd2}, closing the latter
381first if necessary.
Fred Drakec37b65e2001-11-28 07:26:15 +0000382Availability: \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000383\end{funcdesc}
384
Fred Drake88f6ca21999-12-15 19:39:04 +0000385\begin{funcdesc}{fpathconf}{fd, name}
Thomas Woutersf8316632000-07-16 19:01:10 +0000386Return system configuration information relevant to an open file.
Fred Drake88f6ca21999-12-15 19:39:04 +0000387\var{name} specifies the configuration value to retrieve; it may be a
388string which is the name of a defined system value; these names are
Fred Drakec37b65e2001-11-28 07:26:15 +0000389specified in a number of standards (\POSIX.1, \UNIX 95, \UNIX 98, and
Fred Drake88f6ca21999-12-15 19:39:04 +0000390others). Some platforms define additional names as well. The names
391known to the host operating system are given in the
392\code{pathconf_names} dictionary. For configuration variables not
393included in that mapping, passing an integer for \var{name} is also
394accepted.
Fred Drakec37b65e2001-11-28 07:26:15 +0000395Availability: \UNIX.
Fred Drake88f6ca21999-12-15 19:39:04 +0000396
397If \var{name} is a string and is not known, \exception{ValueError} is
398raised. If a specific value for \var{name} is not supported by the
399host system, even if it is included in \code{pathconf_names}, an
400\exception{OSError} is raised with \constant{errno.EINVAL} for the
401error number.
402\end{funcdesc}
403
Fred Drake215fe2f1999-02-02 19:02:35 +0000404\begin{funcdesc}{fstat}{fd}
405Return status for file descriptor \var{fd}, like \function{stat()}.
Fred Drakec37b65e2001-11-28 07:26:15 +0000406Availability: \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000407\end{funcdesc}
408
409\begin{funcdesc}{fstatvfs}{fd}
410Return information about the filesystem containing the file associated
411with file descriptor \var{fd}, like \function{statvfs()}.
Fred Drakec37b65e2001-11-28 07:26:15 +0000412Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000413\end{funcdesc}
414
415\begin{funcdesc}{ftruncate}{fd, length}
416Truncate the file corresponding to file descriptor \var{fd},
417so that it is at most \var{length} bytes in size.
Fred Drakec37b65e2001-11-28 07:26:15 +0000418Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000419\end{funcdesc}
420
Skip Montanarod3725212000-07-19 17:30:58 +0000421\begin{funcdesc}{isatty}{fd}
422Return \code{1} if the file descriptor \var{fd} is open and connected to a
423tty(-like) device, else \code{0}.
Fred Drakec37b65e2001-11-28 07:26:15 +0000424Availability: \UNIX.
Skip Montanarod3725212000-07-19 17:30:58 +0000425\end{funcdesc}
426
Fred Drake215fe2f1999-02-02 19:02:35 +0000427\begin{funcdesc}{lseek}{fd, pos, how}
428Set the current position of file descriptor \var{fd} to position
429\var{pos}, modified by \var{how}: \code{0} to set the position
430relative to the beginning of the file; \code{1} to set it relative to
431the current position; \code{2} to set it relative to the end of the
432file.
Fred Drakec37b65e2001-11-28 07:26:15 +0000433Availability: Macintosh, \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000434\end{funcdesc}
435
436\begin{funcdesc}{open}{file, flags\optional{, mode}}
437Open the file \var{file} and set various flags according to
438\var{flags} and possibly its mode according to \var{mode}.
439The default \var{mode} is \code{0777} (octal), and the current umask
440value is first masked out. Return the file descriptor for the newly
441opened file.
Fred Drakec37b65e2001-11-28 07:26:15 +0000442Availability: Macintosh, \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000443
444For a description of the flag and mode values, see the C run-time
445documentation; flag constants (like \constant{O_RDONLY} and
446\constant{O_WRONLY}) are defined in this module too (see below).
447
448Note: this function is intended for low-level I/O. For normal usage,
449use the built-in function \function{open()}, which returns a ``file
450object'' with \method{read()} and \method{write()} methods (and many
451more).
452\end{funcdesc}
453
Fred Drakec82634c2000-06-28 17:27:48 +0000454\begin{funcdesc}{openpty}{}
455Open a new pseudo-terminal pair. Return a pair of file descriptors
456\code{(\var{master}, \var{slave})} for the pty and the tty,
457respectively. For a (slightly) more portable approach, use the
458\refmodule{pty}\refstmodindex{pty} module.
Fred Drakec37b65e2001-11-28 07:26:15 +0000459Availability: Some flavors of \UNIX.
Fred Drakec82634c2000-06-28 17:27:48 +0000460\end{funcdesc}
461
Fred Drake215fe2f1999-02-02 19:02:35 +0000462\begin{funcdesc}{pipe}{}
463Create a pipe. Return a pair of file descriptors \code{(\var{r},
464\var{w})} usable for reading and writing, respectively.
Fred Drakec37b65e2001-11-28 07:26:15 +0000465Availability: \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000466\end{funcdesc}
467
468\begin{funcdesc}{read}{fd, n}
469Read at most \var{n} bytes from file descriptor \var{fd}.
470Return a string containing the bytes read.
Fred Drakec37b65e2001-11-28 07:26:15 +0000471Availability: Macintosh, \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000472
473Note: this function is intended for low-level I/O and must be applied
474to a file descriptor as returned by \function{open()} or
475\function{pipe()}. To read a ``file object'' returned by the
476built-in function \function{open()} or by \function{popen()} or
477\function{fdopen()}, or \code{sys.stdin}, use its
478\method{read()} or \method{readline()} methods.
479\end{funcdesc}
480
481\begin{funcdesc}{tcgetpgrp}{fd}
482Return the process group associated with the terminal given by
483\var{fd} (an open file descriptor as returned by \function{open()}).
Fred Drakec37b65e2001-11-28 07:26:15 +0000484Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000485\end{funcdesc}
486
487\begin{funcdesc}{tcsetpgrp}{fd, pg}
488Set the process group associated with the terminal given by
489\var{fd} (an open file descriptor as returned by \function{open()})
490to \var{pg}.
Fred Drakec37b65e2001-11-28 07:26:15 +0000491Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000492\end{funcdesc}
493
494\begin{funcdesc}{ttyname}{fd}
495Return a string which specifies the terminal device associated with
496file-descriptor \var{fd}. If \var{fd} is not associated with a terminal
497device, an exception is raised.
Fred Drakec37b65e2001-11-28 07:26:15 +0000498Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000499\end{funcdesc}
500
501\begin{funcdesc}{write}{fd, str}
502Write the string \var{str} to file descriptor \var{fd}.
503Return the number of bytes actually written.
Fred Drakec37b65e2001-11-28 07:26:15 +0000504Availability: Macintosh, \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000505
506Note: this function is intended for low-level I/O and must be applied
507to a file descriptor as returned by \function{open()} or
508\function{pipe()}. To write a ``file object'' returned by the
509built-in function \function{open()} or by \function{popen()} or
510\function{fdopen()}, or \code{sys.stdout} or \code{sys.stderr}, use
511its \method{write()} method.
512\end{funcdesc}
513
514
515The following data items are available for use in constructing the
516\var{flags} parameter to the \function{open()} function.
517
518\begin{datadesc}{O_RDONLY}
519\dataline{O_WRONLY}
520\dataline{O_RDWR}
521\dataline{O_NDELAY}
522\dataline{O_NONBLOCK}
523\dataline{O_APPEND}
524\dataline{O_DSYNC}
525\dataline{O_RSYNC}
526\dataline{O_SYNC}
527\dataline{O_NOCTTY}
528\dataline{O_CREAT}
529\dataline{O_EXCL}
530\dataline{O_TRUNC}
531Options for the \var{flag} argument to the \function{open()} function.
532These can be bit-wise OR'd together.
Fred Drakec37b65e2001-11-28 07:26:15 +0000533Availability: Macintosh, \UNIX, Windows.
Tim Petersc48a3ca2002-01-30 05:49:46 +0000534% XXX O_NDELAY, O_NONBLOCK, O_DSYNC, O_RSYNC, O_SYNC, O_NOCTTY are not on Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000535\end{datadesc}
536
Fred Drake3ac977e2000-08-11 20:19:51 +0000537\begin{datadesc}{O_BINARY}
538Option for the \var{flag} argument to the \function{open()} function.
539This can be bit-wise OR'd together with those listed above.
540Availability: Macintosh, Windows.
541% XXX need to check on the availability of this one.
542\end{datadesc}
543
Tim Petersc48a3ca2002-01-30 05:49:46 +0000544\begin{datadesc}{O_NOINHERIT}
545\dataline{O_SHORT_LIVED}
546\dataline{O_TEMPORARY}
547\dataline{O_RANDOM}
548\dataline{O_SEQUENTIAL}
549\dataline{O_TEXT}
550Options for the \var{flag} argument to the \function{open()} function.
551These can be bit-wise OR'd together.
552Availability: Windows.
553\end{datadesc}
Fred Drake215fe2f1999-02-02 19:02:35 +0000554
555\subsection{Files and Directories \label{os-file-dir}}
556
557\begin{funcdesc}{access}{path, mode}
Fred Drake38e5d272000-04-03 20:13:55 +0000558Check read/write/execute permissions for this process or existence of
559file \var{path}. \var{mode} should be \constant{F_OK} to test the
560existence of \var{path}, or it can be the inclusive OR of one or more
561of \constant{R_OK}, \constant{W_OK}, and \constant{X_OK} to test
562permissions. Return \code{1} if access is allowed, \code{0} if not.
563See the \UNIX{} man page \manpage{access}{2} for more information.
Fred Drakec37b65e2001-11-28 07:26:15 +0000564Availability: \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000565\end{funcdesc}
566
Fred Drake38e5d272000-04-03 20:13:55 +0000567\begin{datadesc}{F_OK}
568 Value to pass as the \var{mode} parameter of \function{access()} to
569 test the existence of \var{path}.
570\end{datadesc}
571
572\begin{datadesc}{R_OK}
573 Value to include in the \var{mode} parameter of \function{access()}
574 to test the readability of \var{path}.
575\end{datadesc}
576
577\begin{datadesc}{W_OK}
578 Value to include in the \var{mode} parameter of \function{access()}
579 to test the writability of \var{path}.
580\end{datadesc}
581
582\begin{datadesc}{X_OK}
583 Value to include in the \var{mode} parameter of \function{access()}
584 to determine if \var{path} can be executed.
585\end{datadesc}
586
Fred Drake6db897c1999-07-12 16:49:30 +0000587\begin{funcdesc}{chdir}{path}
588\index{directory!changing}
589Change the current working directory to \var{path}.
Fred Drakec37b65e2001-11-28 07:26:15 +0000590Availability: Macintosh, \UNIX, Windows.
Fred Drake6db897c1999-07-12 16:49:30 +0000591\end{funcdesc}
592
593\begin{funcdesc}{getcwd}{}
594Return a string representing the current working directory.
Fred Drakec37b65e2001-11-28 07:26:15 +0000595Availability: Macintosh, \UNIX, Windows.
Fred Drake6db897c1999-07-12 16:49:30 +0000596\end{funcdesc}
597
Martin v. Löwis244edc82001-10-04 22:44:26 +0000598\begin{funcdesc}{chroot}{path}
599Change the root directory of the current process to \var{path}.
Fred Drakec37b65e2001-11-28 07:26:15 +0000600Availability: \UNIX.
Martin v. Löwis244edc82001-10-04 22:44:26 +0000601\versionadded{2.2}
602\end{funcdesc}
603
Fred Drake215fe2f1999-02-02 19:02:35 +0000604\begin{funcdesc}{chmod}{path, mode}
605Change the mode of \var{path} to the numeric \var{mode}.
Fred Drakec37b65e2001-11-28 07:26:15 +0000606Availability: \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000607\end{funcdesc}
608
609\begin{funcdesc}{chown}{path, uid, gid}
610Change the owner and group id of \var{path} to the numeric \var{uid}
611and \var{gid}.
Fred Drakec37b65e2001-11-28 07:26:15 +0000612Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000613\end{funcdesc}
614
615\begin{funcdesc}{link}{src, dst}
616Create a hard link pointing to \var{src} named \var{dst}.
Fred Drakec37b65e2001-11-28 07:26:15 +0000617Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000618\end{funcdesc}
619
620\begin{funcdesc}{listdir}{path}
621Return a list containing the names of the entries in the directory.
622The list is in arbitrary order. It does not include the special
623entries \code{'.'} and \code{'..'} even if they are present in the
624directory.
Fred Drakec37b65e2001-11-28 07:26:15 +0000625Availability: Macintosh, \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000626\end{funcdesc}
627
628\begin{funcdesc}{lstat}{path}
629Like \function{stat()}, but do not follow symbolic links.
Fred Drakec37b65e2001-11-28 07:26:15 +0000630Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000631\end{funcdesc}
632
633\begin{funcdesc}{mkfifo}{path\optional{, mode}}
634Create a FIFO (a named pipe) named \var{path} with numeric mode
635\var{mode}. The default \var{mode} is \code{0666} (octal). The current
636umask value is first masked out from the mode.
Fred Drakec37b65e2001-11-28 07:26:15 +0000637Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000638
639FIFOs are pipes that can be accessed like regular files. FIFOs exist
640until they are deleted (for example with \function{os.unlink()}).
641Generally, FIFOs are used as rendezvous between ``client'' and
642``server'' type processes: the server opens the FIFO for reading, and
643the client opens it for writing. Note that \function{mkfifo()}
644doesn't open the FIFO --- it just creates the rendezvous point.
645\end{funcdesc}
646
647\begin{funcdesc}{mkdir}{path\optional{, mode}}
648Create a directory named \var{path} with numeric mode \var{mode}.
649The default \var{mode} is \code{0777} (octal). On some systems,
650\var{mode} is ignored. Where it is used, the current umask value is
651first masked out.
Fred Drakec37b65e2001-11-28 07:26:15 +0000652Availability: Macintosh, \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000653\end{funcdesc}
654
655\begin{funcdesc}{makedirs}{path\optional{, mode}}
656\index{directory!creating}
657Recursive directory creation function. Like \function{mkdir()},
658but makes all intermediate-level directories needed to contain the
659leaf directory. Throws an \exception{error} exception if the leaf
660directory already exists or cannot be created. The default \var{mode}
Fred Drakebbf7a402001-09-28 16:14:18 +0000661is \code{0777} (octal). This function does not properly handle UNC
662paths (only relevant on Windows systems).
Fred Drake215fe2f1999-02-02 19:02:35 +0000663\versionadded{1.5.2}
664\end{funcdesc}
665
Fred Drake88f6ca21999-12-15 19:39:04 +0000666\begin{funcdesc}{pathconf}{path, name}
Thomas Woutersf8316632000-07-16 19:01:10 +0000667Return system configuration information relevant to a named file.
Fred Drake88f6ca21999-12-15 19:39:04 +0000668\var{name} specifies the configuration value to retrieve; it may be a
669string which is the name of a defined system value; these names are
Fred Drake8ee679f2001-07-14 02:50:55 +0000670specified in a number of standards (\POSIX.1, \UNIX 95, \UNIX 98, and
Fred Drake88f6ca21999-12-15 19:39:04 +0000671others). Some platforms define additional names as well. The names
672known to the host operating system are given in the
673\code{pathconf_names} dictionary. For configuration variables not
674included in that mapping, passing an integer for \var{name} is also
675accepted.
Fred Drakec37b65e2001-11-28 07:26:15 +0000676Availability: \UNIX.
Fred Drake88f6ca21999-12-15 19:39:04 +0000677
678If \var{name} is a string and is not known, \exception{ValueError} is
679raised. If a specific value for \var{name} is not supported by the
680host system, even if it is included in \code{pathconf_names}, an
681\exception{OSError} is raised with \constant{errno.EINVAL} for the
682error number.
683\end{funcdesc}
684
685\begin{datadesc}{pathconf_names}
686Dictionary mapping names accepted by \function{pathconf()} and
687\function{fpathconf()} to the integer values defined for those names
688by the host operating system. This can be used to determine the set
689of names known to the system.
690Availability: \UNIX.
691\end{datadesc}
692
Fred Drake215fe2f1999-02-02 19:02:35 +0000693\begin{funcdesc}{readlink}{path}
694Return a string representing the path to which the symbolic link
Fred Drakedc9e7e42001-05-29 18:13:06 +0000695points. The result may be either an absolute or relative pathname; if
696it is relative, it may be converted to an absolute pathname using
697\code{os.path.join(os.path.dirname(\var{path}), \var{result})}.
Fred Drakec37b65e2001-11-28 07:26:15 +0000698Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000699\end{funcdesc}
700
701\begin{funcdesc}{remove}{path}
Fred Drakedc9e7e42001-05-29 18:13:06 +0000702Remove the file \var{path}. If \var{path} is a directory,
703\exception{OSError} is raised; see \function{rmdir()} below to remove
704a directory. This is identical to the \function{unlink()} function
705documented below. On Windows, attempting to remove a file that is in
706use causes an exception to be raised; on \UNIX, the directory entry is
707removed but the storage allocated to the file is not made available
708until the original file is no longer in use.
Fred Drakec37b65e2001-11-28 07:26:15 +0000709Availability: Macintosh, \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000710\end{funcdesc}
711
712\begin{funcdesc}{removedirs}{path}
713\index{directory!deleting}
714Recursive directory removal function. Works like
715\function{rmdir()} except that, if the leaf directory is
716successfully removed, directories corresponding to rightmost path
717segments will be pruned way until either the whole path is consumed or
718an error is raised (which is ignored, because it generally means that
719a parent directory is not empty). Throws an \exception{error}
720exception if the leaf directory could not be successfully removed.
721\versionadded{1.5.2}
722\end{funcdesc}
723
724\begin{funcdesc}{rename}{src, dst}
Fred Drakedc9e7e42001-05-29 18:13:06 +0000725Rename the file or directory \var{src} to \var{dst}. If \var{dst} is
726a directory, \exception{OSError} will be raised. On \UNIX, if
727\var{dst} exists and is a file, it will be removed silently if the
728user has permission. The operation may fail on some \UNIX{} flavors
Skip Montanarob9d973d2001-06-04 15:31:17 +0000729if \var{src} and \var{dst} are on different filesystems. If
Fred Drakedc9e7e42001-05-29 18:13:06 +0000730successful, the renaming will be an atomic operation (this is a
731\POSIX{} requirement). On Windows, if \var{dst} already exists,
732\exception{OSError} will be raised even if it is a file; there may be
733no way to implement an atomic rename when \var{dst} names an existing
734file.
Fred Drakec37b65e2001-11-28 07:26:15 +0000735Availability: Macintosh, \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000736\end{funcdesc}
737
738\begin{funcdesc}{renames}{old, new}
739Recursive directory or file renaming function.
740Works like \function{rename()}, except creation of any intermediate
741directories needed to make the new pathname good is attempted first.
742After the rename, directories corresponding to rightmost path segments
743of the old name will be pruned away using \function{removedirs()}.
744
745Note: this function can fail with the new directory structure made if
746you lack permissions needed to remove the leaf directory or file.
747\versionadded{1.5.2}
748\end{funcdesc}
749
750\begin{funcdesc}{rmdir}{path}
751Remove the directory \var{path}.
Fred Drakec37b65e2001-11-28 07:26:15 +0000752Availability: Macintosh, \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000753\end{funcdesc}
754
755\begin{funcdesc}{stat}{path}
756Perform a \cfunction{stat()} system call on the given path. The
Fred Drake6995bb62001-11-29 20:48:44 +0000757return value is an object whose attributes correspond to the members of
758the \ctype{stat} structure, namely:
759\member{st_mode} (protection bits),
760\member{st_ino} (inode number),
761\member{st_dev} (device),
762\member{st_nlink} (number of hard links,
763\member{st_uid} (user ID of owner),
764\member{st_gid} (group ID of owner),
765\member{st_size} (size of file, in bytes),
766\member{st_atime} (time of most recent access),
767\member{st_mtime} (time of most recent content modification),
768\member{st_ctime}
769(time of most recent content modification or metadata change).
770
771On some Unix systems (such as Linux), the following attributes may
772also be available:
773\member{st_blocks} (number of blocks allocated for file),
774\member{st_blksize} (filesystem blocksize),
775\member{st_rdev} (type of device if an inode device).
776
777On Mac OS systems, the following attributes may also be available:
778\member{st_rsize},
779\member{st_creator},
780\member{st_type}.
781
782On RISCOS systems, the following attributes are also available:
783\member{st_ftype} (file type),
784\member{st_attrs} (attributes),
785\member{st_obtype} (object type).
786
787For backward compatibility, the return value of \function{stat()} is
788also accessible as a tuple of at least 10 integers giving the most
789important (and portable) members of the \ctype{stat} structure, in the
Fred Drake215fe2f1999-02-02 19:02:35 +0000790order
Fred Drake6995bb62001-11-29 20:48:44 +0000791\member{st_mode},
792\member{st_ino},
793\member{st_dev},
794\member{st_nlink},
795\member{st_uid},
796\member{st_gid},
797\member{st_size},
798\member{st_atime},
799\member{st_mtime},
800\member{st_ctime}.
Fred Drake21c9df72000-10-14 05:46:11 +0000801More items may be added at the end by some implementations. Note that
Fred Drake8ee679f2001-07-14 02:50:55 +0000802on the Mac OS, the time values are floating point values, like all
803time values on the Mac OS.
Fred Drake6995bb62001-11-29 20:48:44 +0000804The standard module \refmodule{stat}\refstmodindex{stat} defines
805functions and constants that are useful for extracting information
806from a \ctype{stat} structure.
Fred Drake8ee679f2001-07-14 02:50:55 +0000807(On Windows, some items are filled with dummy values.)
Fred Drakec37b65e2001-11-28 07:26:15 +0000808Availability: Macintosh, \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000809
Fred Drake6995bb62001-11-29 20:48:44 +0000810\versionchanged
811[Added access to values as attributes of the returned object]{2.2}
Fred Drake215fe2f1999-02-02 19:02:35 +0000812\end{funcdesc}
813
814\begin{funcdesc}{statvfs}{path}
815Perform a \cfunction{statvfs()} system call on the given path. The
Fred Drake6995bb62001-11-29 20:48:44 +0000816return value is an object whose attributes describe the filesystem on
817the given path, and correspond to the members of the
818\ctype{statvfs} structure, namely:
819\member{f_frsize},
820\member{f_blocks},
821\member{f_bfree},
822\member{f_bavail},
823\member{f_files},
824\member{f_ffree},
825\member{f_favail},
826\member{f_flag},
827\member{f_namemax}.
Fred Drakec37b65e2001-11-28 07:26:15 +0000828Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000829
Fred Drake6995bb62001-11-29 20:48:44 +0000830For backward compatibility, the return value is also accessible as a
831tuple whose values correspond to the attributes, in the order given above.
832The standard module \refmodule{statvfs}\refstmodindex{statvfs}
Fred Drake215fe2f1999-02-02 19:02:35 +0000833defines constants that are useful for extracting information
Fred Drake6995bb62001-11-29 20:48:44 +0000834from a \ctype{statvfs} structure when accessing it as a sequence; this
835remains useful when writing code that needs to work with versions of
836Python that don't support accessing the fields as attributes.
837
838\versionchanged
839[Added access to values as attributes of the returned object]{2.2}
Fred Drake215fe2f1999-02-02 19:02:35 +0000840\end{funcdesc}
841
842\begin{funcdesc}{symlink}{src, dst}
843Create a symbolic link pointing to \var{src} named \var{dst}.
Fred Drakec37b65e2001-11-28 07:26:15 +0000844Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000845\end{funcdesc}
846
Fred Drake18f7a451999-12-09 22:11:43 +0000847\begin{funcdesc}{tempnam}{\optional{dir\optional{, prefix}}}
848Return a unique path name that is reasonable for creating a temporary
849file. This will be an absolute path that names a potential directory
850entry in the directory \var{dir} or a common location for temporary
851files if \var{dir} is omitted or \code{None}. If given and not
852\code{None}, \var{prefix} is used to provide a short prefix to the
853filename. Applications are responsible for properly creating and
854managing files created using paths returned by \function{tempnam()};
855no automatic cleanup is provided.
Fred Drake938a8d72001-10-09 18:07:04 +0000856\warning{Use of \function{tempnam()} is vulnerable to symlink attacks;
857consider using \function{tmpfile()} instead.}
Fred Drakeefaef132001-07-17 20:39:18 +0000858Availability: \UNIX, Windows.
Fred Drake18f7a451999-12-09 22:11:43 +0000859\end{funcdesc}
860
861\begin{funcdesc}{tmpnam}{}
862Return a unique path name that is reasonable for creating a temporary
863file. This will be an absolute path that names a potential directory
864entry in a common location for temporary files. Applications are
865responsible for properly creating and managing files created using
866paths returned by \function{tmpnam()}; no automatic cleanup is
867provided.
Fred Drake938a8d72001-10-09 18:07:04 +0000868\warning{Use of \function{tmpnam()} is vulnerable to symlink attacks;
869consider using \function{tmpfile()} instead.}
Fred Drakeefaef132001-07-17 20:39:18 +0000870Availability: \UNIX, Windows.
Fred Drake18f7a451999-12-09 22:11:43 +0000871\end{funcdesc}
872
873\begin{datadesc}{TMP_MAX}
874The maximum number of unique names that \function{tmpnam()} will
875generate before reusing names.
876\end{datadesc}
877
Fred Drake215fe2f1999-02-02 19:02:35 +0000878\begin{funcdesc}{unlink}{path}
879Remove the file \var{path}. This is the same function as
880\function{remove()}; the \function{unlink()} name is its traditional
881\UNIX{} name.
Fred Drakec37b65e2001-11-28 07:26:15 +0000882Availability: Macintosh, \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000883\end{funcdesc}
884
Barry Warsaw93a8eac2000-05-01 16:18:22 +0000885\begin{funcdesc}{utime}{path, times}
886Set the access and modified times of the file specified by \var{path}.
887If \var{times} is \code{None}, then the file's access and modified
888times are set to the current time. Otherwise, \var{times} must be a
Fred Drakee06d0252000-05-02 17:29:35 +00008892-tuple of numbers, of the form \code{(\var{atime}, \var{mtime})}
890which is used to set the access and modified times, respectively.
Fred Drake4a152632000-10-19 05:33:46 +0000891\versionchanged[Added support for \code{None} for \var{times}]{2.0}
Fred Drakec37b65e2001-11-28 07:26:15 +0000892Availability: Macintosh, \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000893\end{funcdesc}
894
895
896\subsection{Process Management \label{os-process}}
897
Fred Drake18f7a451999-12-09 22:11:43 +0000898These functions may be used to create and manage processes.
Fred Drake215fe2f1999-02-02 19:02:35 +0000899
Fred Drake7be31152000-09-23 05:22:07 +0000900The various \function{exec*()} functions take a list of arguments for
901the new program loaded into the process. In each case, the first of
902these arguments is passed to the new program as its own name rather
903than as an argument a user may have typed on a command line. For the
904C programmer, this is the \code{argv[0]} passed to a program's
905\cfunction{main()}. For example, \samp{os.execv('/bin/echo', ['foo',
906'bar'])} will only print \samp{bar} on standard output; \samp{foo}
907will seem to be ignored.
908
Fred Drake215fe2f1999-02-02 19:02:35 +0000909
Fred Drake18f7a451999-12-09 22:11:43 +0000910\begin{funcdesc}{abort}{}
911Generate a \constant{SIGABRT} signal to the current process. On
912\UNIX, the default behavior is to produce a core dump; on Windows, the
913process immediately returns an exit code of \code{3}. Be aware that
914programs which use \function{signal.signal()} to register a handler
915for \constant{SIGABRT} will behave differently.
916Availability: \UNIX, Windows.
917\end{funcdesc}
918
Fred Drakedb7287c2001-10-18 18:58:30 +0000919\begin{funcdesc}{execl}{path, arg0, arg1, \moreargs}
920\funcline{execle}{path, arg0, arg1, \moreargs, env}
921\funcline{execlp}{file, arg0, arg1, \moreargs}
922\funcline{execlpe}{file, arg0, arg1, \moreargs, env}
923\funcline{execv}{path, args}
924\funcline{execve}{path, args, env}
925\funcline{execvp}{file, args}
926\funcline{execvpe}{file, args, env}
927These functions all execute a new program, replacing the current
928process; they do not return. On \UNIX, the new executable is loaded
929into the current process, and will have the same process ID as the
930caller. Errors will be reported as \exception{OSError} exceptions.
Fred Drake215fe2f1999-02-02 19:02:35 +0000931
Fred Drakedb7287c2001-10-18 18:58:30 +0000932The \character{l} and \character{v} variants of the
933\function{exec*()} functions differ in how command-line arguments are
934passed. The \character{l} variants are perhaps the easiest to work
935with if the number of parameters is fixed when the code is written;
936the individual parameters simply become additional parameters to the
937\function{execl*()} functions. The \character{v} variants are good
938when the number of parameters is variable, with the arguments being
939passed in a list or tuple as the \var{args} parameter. In either
940case, the arguments to the child process must start with the name of
941the command being run.
Fred Drake215fe2f1999-02-02 19:02:35 +0000942
Fred Drakedb7287c2001-10-18 18:58:30 +0000943The variants which include a \character{p} near the end
944(\function{execlp()}, \function{execlpe()}, \function{execvp()},
945and \function{execvpe()}) will use the \envvar{PATH} environment
946variable to locate the program \var{file}. When the environment is
947being replaced (using one of the \function{exec*e()} variants,
948discussed in the next paragraph), the
949new environment is used as the source of the \envvar{PATH} variable.
950The other variants, \function{execl()}, \function{execle()},
951\function{execv()}, and \function{execve()}, will not use the
952\envvar{PATH} variable to locate the executable; \var{path} must
953contain an appropriate absolute or relative path.
Fred Drake215fe2f1999-02-02 19:02:35 +0000954
Fred Drakedb7287c2001-10-18 18:58:30 +0000955For \function{execle()}, \function{execlpe()}, \function{execve()},
956and \function{execvpe()} (note that these all end in \character{e}),
957the \var{env} parameter must be a mapping which is used to define the
958environment variables for the new process; the \function{execl()},
959\function{execlp()}, \function{execv()}, and \function{execvp()}
960all cause the new process to inherit the environment of the current
961process.
962Availability: \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000963\end{funcdesc}
964
965\begin{funcdesc}{_exit}{n}
966Exit to the system with status \var{n}, without calling cleanup
967handlers, flushing stdio buffers, etc.
Fred Drakec37b65e2001-11-28 07:26:15 +0000968Availability: \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +0000969
970Note: the standard way to exit is \code{sys.exit(\var{n})}.
971\function{_exit()} should normally only be used in the child process
972after a \function{fork()}.
973\end{funcdesc}
974
975\begin{funcdesc}{fork}{}
976Fork a child process. Return \code{0} in the child, the child's
977process id in the parent.
Fred Drakec37b65e2001-11-28 07:26:15 +0000978Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000979\end{funcdesc}
980
Fred Drakec82634c2000-06-28 17:27:48 +0000981\begin{funcdesc}{forkpty}{}
982Fork a child process, using a new pseudo-terminal as the child's
983controlling terminal. Return a pair of \code{(\var{pid}, \var{fd})},
984where \var{pid} is \code{0} in the child, the new child's process id
Fred Drake6995bb62001-11-29 20:48:44 +0000985in the parent, and \var{fd} is the file descriptor of the master end
Fred Drakec82634c2000-06-28 17:27:48 +0000986of the pseudo-terminal. For a more portable approach, use the
987\refmodule{pty} module.
Fred Drakec37b65e2001-11-28 07:26:15 +0000988Availability: Some flavors of \UNIX.
Fred Drakec82634c2000-06-28 17:27:48 +0000989\end{funcdesc}
990
Fred Drake215fe2f1999-02-02 19:02:35 +0000991\begin{funcdesc}{kill}{pid, sig}
992\index{process!killing}
993\index{process!signalling}
Fred Drake5c798312001-12-21 03:58:47 +0000994Kill the process \var{pid} with signal \var{sig}. Constants for the
995specific signals available on the host platform are defined in the
996\refmodule{signal} module.
Fred Drakec37b65e2001-11-28 07:26:15 +0000997Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +0000998\end{funcdesc}
999
1000\begin{funcdesc}{nice}{increment}
1001Add \var{increment} to the process's ``niceness''. Return the new
1002niceness.
Fred Drakec37b65e2001-11-28 07:26:15 +00001003Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +00001004\end{funcdesc}
1005
1006\begin{funcdesc}{plock}{op}
1007Lock program segments into memory. The value of \var{op}
1008(defined in \code{<sys/lock.h>}) determines which segments are locked.
Fred Drakec37b65e2001-11-28 07:26:15 +00001009Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +00001010\end{funcdesc}
1011
Fred Drake046f4d82001-06-11 15:21:48 +00001012\begin{funcdescni}{popen}{\unspecified}
1013\funclineni{popen2}{\unspecified}
1014\funclineni{popen3}{\unspecified}
1015\funclineni{popen4}{\unspecified}
1016Run child processes, returning opened pipes for communications. These
1017functions are described in section \ref{os-newstreams}.
1018\end{funcdescni}
1019
Fred Drake739282d2001-08-16 21:21:28 +00001020\begin{funcdesc}{spawnl}{mode, path, \moreargs}
1021\funcline{spawnle}{mode, path, \moreargs, env}
Fred Drakedb7287c2001-10-18 18:58:30 +00001022\funcline{spawnlp}{mode, file, \moreargs}
1023\funcline{spawnlpe}{mode, file, \moreargs, env}
Fred Drake739282d2001-08-16 21:21:28 +00001024\funcline{spawnv}{mode, path, args}
1025\funcline{spawnve}{mode, path, args, env}
Fred Drakedb7287c2001-10-18 18:58:30 +00001026\funcline{spawnvp}{mode, file, args}
1027\funcline{spawnvpe}{mode, file, args, env}
Fred Drake739282d2001-08-16 21:21:28 +00001028Execute the program \var{path} in a new process. If \var{mode} is
1029\constant{P_NOWAIT}, this function returns the process ID of the new
Tim Petersb4041452001-12-06 23:37:17 +00001030process; if \var{mode} is \constant{P_WAIT}, returns the process's
Fred Drake739282d2001-08-16 21:21:28 +00001031exit code if it exits normally, or \code{-\var{signal}}, where
1032\var{signal} is the signal that killed the process.
Fred Drake215fe2f1999-02-02 19:02:35 +00001033
Fred Drake739282d2001-08-16 21:21:28 +00001034The \character{l} and \character{v} variants of the
1035\function{spawn*()} functions differ in how command-line arguments are
1036passed. The \character{l} variants are perhaps the easiest to work
1037with if the number of parameters is fixed when the code is written;
1038the individual parameters simply become additional parameters to the
1039\function{spawnl*()} functions. The \character{v} variants are good
1040when the number of parameters is variable, with the arguments being
1041passed in a list or tuple as the \var{args} parameter. In either
1042case, the arguments to the child process must start with the name of
1043the command being run.
1044
Fred Drakedb7287c2001-10-18 18:58:30 +00001045The variants which include a second \character{p} near the end
1046(\function{spawnlp()}, \function{spawnlpe()}, \function{spawnvp()},
1047and \function{spawnvpe()}) will use the \envvar{PATH} environment
1048variable to locate the program \var{file}. When the environment is
1049being replaced (using one of the \function{spawn*e()} variants,
1050discussed in the next paragraph), the new environment is used as the
1051source of the \envvar{PATH} variable. The other variants,
1052\function{spawnl()}, \function{spawnle()}, \function{spawnv()}, and
1053\function{spawnve()}, will not use the \envvar{PATH} variable to
1054locate the executable; \var{path} must contain an appropriate absolute
1055or relative path.
1056
1057For \function{spawnle()}, \function{spawnlpe()}, \function{spawnve()},
1058and \function{spawnvpe()} (note that these all end in \character{e}),
1059the \var{env} parameter must be a mapping which is used to define the
1060environment variables for the new process; the \function{spawnl()},
1061\function{spawnlp()}, \function{spawnv()}, and \function{spawnvp()}
1062all cause the new process to inherit the environment of the current
1063process.
1064
Fred Drake739282d2001-08-16 21:21:28 +00001065As an example, the following calls to \function{spawnlp()} and
1066\function{spawnvpe()} are equivalent:
1067
1068\begin{verbatim}
1069import os
1070os.spawnlp(os.P_WAIT, 'cp', 'cp', 'index.html', '/dev/null')
1071
1072L = ['cp', 'index.html', '/dev/null']
1073os.spawnvpe(os.P_WAIT, 'cp', L, os.environ)
1074\end{verbatim}
1075
Fred Drake8c8e8712001-12-20 17:24:11 +00001076Availability: \UNIX, Windows. \function{spawnlp()},
1077\function{spawnlpe()}, \function{spawnvp()} and \function{spawnvpe()}
1078are not available on Windows.
Fred Drake0b9bc202001-06-11 18:25:34 +00001079\versionadded{1.6}
Fred Drake215fe2f1999-02-02 19:02:35 +00001080\end{funcdesc}
1081
Fred Drake938a8d72001-10-09 18:07:04 +00001082\begin{datadesc}{P_NOWAIT}
Fred Drake9329e5e1999-02-16 19:40:19 +00001083\dataline{P_NOWAITO}
Fred Drake938a8d72001-10-09 18:07:04 +00001084Possible values for the \var{mode} parameter to the \function{spawn*()}
1085family of functions. If either of these values is given, the
1086\function{spawn*()} functions will return as soon as the new process
1087has been created, with the process ID as the return value.
Fred Drakec37b65e2001-11-28 07:26:15 +00001088Availability: \UNIX, Windows.
Fred Drake0b9bc202001-06-11 18:25:34 +00001089\versionadded{1.6}
Fred Drake15861b22000-02-29 05:19:38 +00001090\end{datadesc}
1091
Fred Drake938a8d72001-10-09 18:07:04 +00001092\begin{datadesc}{P_WAIT}
1093Possible value for the \var{mode} parameter to the \function{spawn*()}
1094family of functions. If this is given as \var{mode}, the
1095\function{spawn*()} functions will not return until the new process
1096has run to completion and will return the exit code of the process the
1097run is successful, or \code{-\var{signal}} if a signal kills the
1098process.
Fred Drakec37b65e2001-11-28 07:26:15 +00001099Availability: \UNIX, Windows.
Fred Drake938a8d72001-10-09 18:07:04 +00001100\versionadded{1.6}
1101\end{datadesc}
1102
1103\begin{datadesc}{P_DETACH}
1104\dataline{P_OVERLAY}
1105Possible values for the \var{mode} parameter to the
1106\function{spawn*()} family of functions. These are less portable than
1107those listed above.
1108\constant{P_DETACH} is similar to \constant{P_NOWAIT}, but the new
1109process is detached from the console of the calling process.
1110If \constant{P_OVERLAY} is used, the current process will be replaced;
1111the \function{spawn*()} function will not return.
Fred Drake215fe2f1999-02-02 19:02:35 +00001112Availability: Windows.
Fred Drake0b9bc202001-06-11 18:25:34 +00001113\versionadded{1.6}
Fred Drake215fe2f1999-02-02 19:02:35 +00001114\end{datadesc}
1115
Fred Drake4ce4f2e2000-09-29 04:15:19 +00001116\begin{funcdesc}{startfile}{path}
1117Start a file with its associated application. This acts like
1118double-clicking the file in Windows Explorer, or giving the file name
Fred Drake8ee679f2001-07-14 02:50:55 +00001119as an argument to the \program{start} command from the interactive
1120command shell: the file is opened with whatever application (if any)
1121its extension is associated.
Fred Drake4ce4f2e2000-09-29 04:15:19 +00001122
1123\function{startfile()} returns as soon as the associated application
1124is launched. There is no option to wait for the application to close,
1125and no way to retrieve the application's exit status. The \var{path}
1126parameter is relative to the current directory. If you want to use an
1127absolute path, make sure the first character is not a slash
1128(\character{/}); the underlying Win32 \cfunction{ShellExecute()}
Fred Drake8a2adcf2001-07-23 19:20:56 +00001129function doesn't work if it is. Use the \function{os.path.normpath()}
Fred Drake4ce4f2e2000-09-29 04:15:19 +00001130function to ensure that the path is properly encoded for Win32.
1131Availability: Windows.
1132\versionadded{2.0}
1133\end{funcdesc}
1134
Fred Drake215fe2f1999-02-02 19:02:35 +00001135\begin{funcdesc}{system}{command}
1136Execute the command (a string) in a subshell. This is implemented by
1137calling the Standard C function \cfunction{system()}, and has the
Fred Drakeec6baaf1999-04-21 18:13:31 +00001138same limitations. Changes to \code{posix.environ}, \code{sys.stdin},
Fred Drake215fe2f1999-02-02 19:02:35 +00001139etc.\ are not reflected in the environment of the executed command.
1140The return value is the exit status of the process encoded in the
Fred Drake7a621281999-06-10 15:07:05 +00001141format specified for \function{wait()}, except on Windows 95 and 98,
Fred Drakea88ef001999-06-18 19:11:25 +00001142where it is always \code{0}. Note that \POSIX{} does not specify the
1143meaning of the return value of the C \cfunction{system()} function,
1144so the return value of the Python function is system-dependent.
Fred Drakec37b65e2001-11-28 07:26:15 +00001145Availability: \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +00001146\end{funcdesc}
1147
1148\begin{funcdesc}{times}{}
Fred Drake8ee679f2001-07-14 02:50:55 +00001149Return a 5-tuple of floating point numbers indicating accumulated
1150(processor or other)
Fred Drake215fe2f1999-02-02 19:02:35 +00001151times, in seconds. The items are: user time, system time, children's
1152user time, children's system time, and elapsed real time since a fixed
Fred Drakeec6baaf1999-04-21 18:13:31 +00001153point in the past, in that order. See the \UNIX{} manual page
1154\manpage{times}{2} or the corresponding Windows Platform API
1155documentation.
Fred Drakec37b65e2001-11-28 07:26:15 +00001156Availability: \UNIX, Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +00001157\end{funcdesc}
1158
1159\begin{funcdesc}{wait}{}
1160Wait for completion of a child process, and return a tuple containing
1161its pid and exit status indication: a 16-bit number, whose low byte is
1162the signal number that killed the process, and whose high byte is the
1163exit status (if the signal number is zero); the high bit of the low
1164byte is set if a core file was produced.
Fred Drakec37b65e2001-11-28 07:26:15 +00001165Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +00001166\end{funcdesc}
1167
1168\begin{funcdesc}{waitpid}{pid, options}
Fred Drake31e5e371999-08-13 13:36:33 +00001169Wait for completion of a child process given by process id \var{pid},
1170and return a tuple containing its process id and exit status
1171indication (encoded as for \function{wait()}). The semantics of the
1172call are affected by the value of the integer \var{options}, which
1173should be \code{0} for normal operation.
Fred Drakec37b65e2001-11-28 07:26:15 +00001174Availability: \UNIX.
Fred Drake31e5e371999-08-13 13:36:33 +00001175
1176If \var{pid} is greater than \code{0}, \function{waitpid()} requests
1177status information for that specific process. If \var{pid} is
1178\code{0}, the request is for the status of any child in the process
1179group of the current process. If \var{pid} is \code{-1}, the request
1180pertains to any child of the current process. If \var{pid} is less
1181than \code{-1}, status is requested for any process in the process
1182group \code{-\var{pid}} (the absolute value of \var{pid}).
Fred Drake215fe2f1999-02-02 19:02:35 +00001183\end{funcdesc}
1184
1185\begin{datadesc}{WNOHANG}
1186The option for \function{waitpid()} to avoid hanging if no child
1187process status is available immediately.
Fred Drakec37b65e2001-11-28 07:26:15 +00001188Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +00001189\end{datadesc}
1190
Fred Drake38e5d272000-04-03 20:13:55 +00001191The following functions take a process status code as returned by
1192\function{system()}, \function{wait()}, or \function{waitpid()} as a
1193parameter. They may be used to determine the disposition of a
1194process.
Fred Drake215fe2f1999-02-02 19:02:35 +00001195
1196\begin{funcdesc}{WIFSTOPPED}{status}
1197Return true if the process has been stopped.
Fred Drakec37b65e2001-11-28 07:26:15 +00001198Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +00001199\end{funcdesc}
1200
1201\begin{funcdesc}{WIFSIGNALED}{status}
1202Return true if the process exited due to a signal.
Fred Drakec37b65e2001-11-28 07:26:15 +00001203Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +00001204\end{funcdesc}
1205
1206\begin{funcdesc}{WIFEXITED}{status}
1207Return true if the process exited using the \manpage{exit}{2} system
1208call.
Fred Drakec37b65e2001-11-28 07:26:15 +00001209Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +00001210\end{funcdesc}
1211
1212\begin{funcdesc}{WEXITSTATUS}{status}
1213If \code{WIFEXITED(\var{status})} is true, return the integer
1214parameter to the \manpage{exit}{2} system call. Otherwise, the return
1215value is meaningless.
Fred Drakec37b65e2001-11-28 07:26:15 +00001216Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +00001217\end{funcdesc}
1218
1219\begin{funcdesc}{WSTOPSIG}{status}
Fred Drake35c3ffd1999-03-04 14:08:10 +00001220Return the signal which caused the process to stop.
Fred Drakec37b65e2001-11-28 07:26:15 +00001221Availability: \UNIX.
Fred Drake35c3ffd1999-03-04 14:08:10 +00001222\end{funcdesc}
1223
1224\begin{funcdesc}{WTERMSIG}{status}
Fred Drake215fe2f1999-02-02 19:02:35 +00001225Return the signal which caused the process to exit.
Fred Drakec37b65e2001-11-28 07:26:15 +00001226Availability: \UNIX.
Fred Drake215fe2f1999-02-02 19:02:35 +00001227\end{funcdesc}
1228
1229
Thomas Woutersf8316632000-07-16 19:01:10 +00001230\subsection{Miscellaneous System Information \label{os-path}}
Fred Drake88f6ca21999-12-15 19:39:04 +00001231
1232
1233\begin{funcdesc}{confstr}{name}
1234Return string-valued system configuration values.
1235\var{name} specifies the configuration value to retrieve; it may be a
1236string which is the name of a defined system value; these names are
Fred Drake8ee679f2001-07-14 02:50:55 +00001237specified in a number of standards (\POSIX, \UNIX 95, \UNIX 98, and
Fred Drake88f6ca21999-12-15 19:39:04 +00001238others). Some platforms define additional names as well. The names
1239known to the host operating system are given in the
1240\code{confstr_names} dictionary. For configuration variables not
1241included in that mapping, passing an integer for \var{name} is also
1242accepted.
Fred Drakec37b65e2001-11-28 07:26:15 +00001243Availability: \UNIX.
Fred Drake88f6ca21999-12-15 19:39:04 +00001244
1245If the configuration value specified by \var{name} isn't defined, the
1246empty string is returned.
1247
1248If \var{name} is a string and is not known, \exception{ValueError} is
1249raised. If a specific value for \var{name} is not supported by the
1250host system, even if it is included in \code{confstr_names}, an
1251\exception{OSError} is raised with \constant{errno.EINVAL} for the
1252error number.
1253\end{funcdesc}
1254
1255\begin{datadesc}{confstr_names}
1256Dictionary mapping names accepted by \function{confstr()} to the
1257integer values defined for those names by the host operating system.
1258This can be used to determine the set of names known to the system.
1259Availability: \UNIX.
1260\end{datadesc}
1261
1262\begin{funcdesc}{sysconf}{name}
1263Return integer-valued system configuration values.
1264If the configuration value specified by \var{name} isn't defined,
1265\code{-1} is returned. The comments regarding the \var{name}
1266parameter for \function{confstr()} apply here as well; the dictionary
1267that provides information on the known names is given by
1268\code{sysconf_names}.
Fred Drakec37b65e2001-11-28 07:26:15 +00001269Availability: \UNIX.
Fred Drake88f6ca21999-12-15 19:39:04 +00001270\end{funcdesc}
1271
1272\begin{datadesc}{sysconf_names}
1273Dictionary mapping names accepted by \function{sysconf()} to the
1274integer values defined for those names by the host operating system.
1275This can be used to determine the set of names known to the system.
1276Availability: \UNIX.
1277\end{datadesc}
1278
Fred Drake215fe2f1999-02-02 19:02:35 +00001279
1280The follow data values are used to support path manipulation
1281operations. These are defined for all platforms.
1282
1283Higher-level operations on pathnames are defined in the
1284\refmodule{os.path} module.
1285
1286
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00001287\begin{datadesc}{curdir}
Fred Drake8ee679f2001-07-14 02:50:55 +00001288The constant string used by the operating system to refer to the current
1289directory.
Fred Drake907e76b2001-07-06 20:30:11 +00001290For example: \code{'.'} for \POSIX{} or \code{':'} for the Macintosh.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00001291\end{datadesc}
1292
1293\begin{datadesc}{pardir}
Fred Drake8ee679f2001-07-14 02:50:55 +00001294The constant string used by the operating system to refer to the parent
1295directory.
Fred Drake907e76b2001-07-06 20:30:11 +00001296For example: \code{'..'} for \POSIX{} or \code{'::'} for the Macintosh.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00001297\end{datadesc}
1298
1299\begin{datadesc}{sep}
Fred Drake8ee679f2001-07-14 02:50:55 +00001300The character used by the operating system to separate pathname components,
Fred Drake907e76b2001-07-06 20:30:11 +00001301for example, \character{/} for \POSIX{} or \character{:} for the
1302Macintosh. Note that knowing this is not sufficient to be able to
1303parse or concatenate pathnames --- use \function{os.path.split()} and
Fred Drake1a3c2a01998-08-06 15:18:23 +00001304\function{os.path.join()} --- but it is occasionally useful.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00001305\end{datadesc}
1306
Guido van Rossumb2afc811997-08-29 22:37:44 +00001307\begin{datadesc}{altsep}
Fred Drake8ee679f2001-07-14 02:50:55 +00001308An alternative character used by the operating system to separate pathname
1309components, or \code{None} if only one separator character exists. This is
1310set to \character{/} on DOS and Windows systems where \code{sep} is a
1311backslash.
Guido van Rossumb2afc811997-08-29 22:37:44 +00001312\end{datadesc}
1313
Guido van Rossum470be141995-03-17 16:07:09 +00001314\begin{datadesc}{pathsep}
Fred Drake8ee679f2001-07-14 02:50:55 +00001315The character conventionally used by the operating system to separate
1316search patch components (as in \envvar{PATH}), such as \character{:} for
1317\POSIX{} or \character{;} for DOS and Windows.
Guido van Rossum9c59ce91998-06-30 15:54:27 +00001318\end{datadesc}
1319
Guido van Rossum470be141995-03-17 16:07:09 +00001320\begin{datadesc}{defpath}
Fred Drake6995bb62001-11-29 20:48:44 +00001321The default search path used by \function{exec*p*()} and
1322\function{spawn*p*()} if the environment doesn't have a \code{'PATH'}
1323key.
Guido van Rossum470be141995-03-17 16:07:09 +00001324\end{datadesc}
1325
Fred Drake215fe2f1999-02-02 19:02:35 +00001326\begin{datadesc}{linesep}
1327The string used to separate (or, rather, terminate) lines on the
Fred Drake907e76b2001-07-06 20:30:11 +00001328current platform. This may be a single character, such as \code{'\e
Fred Drake6995bb62001-11-29 20:48:44 +00001329n'} for \POSIX{} or \code{'\e r'} for Mac OS, or multiple characters,
Fred Drake8ee679f2001-07-14 02:50:55 +00001330for example, \code{'\e r\e n'} for DOS and Windows.
Fred Drake215fe2f1999-02-02 19:02:35 +00001331\end{datadesc}