]> granicus.if.org Git - python/commitdiff
Patch #1393157: os.startfile() now has an optional argument to specify
authorGeorg Brandl <georg@python.org>
Sat, 18 Feb 2006 22:29:33 +0000 (22:29 +0000)
committerGeorg Brandl <georg@python.org>
Sat, 18 Feb 2006 22:29:33 +0000 (22:29 +0000)
a "command verb" to invoke on the file.

Doc/lib/libos.tex
Misc/NEWS
Modules/posixmodule.c

index a98820c23eba60e47101bdc3eb4801331a9de32b..60a831c40ad21ad8ca0bc7bcb50dae12981dbe1d 100644 (file)
@@ -1629,13 +1629,21 @@ Availability: Windows.
 \versionadded{1.6}
 \end{datadesc}
 
-\begin{funcdesc}{startfile}{path}
-Start a file with its associated application.  This acts like
+\begin{funcdesc}{startfile}{path\optional{, operation}}
+Start a file with its associated application.
+
+When \var{operation} is not specified or \code{'open'}, this acts like
 double-clicking the file in Windows Explorer, or giving the file name
 as an argument to the \program{start} command from the interactive
 command shell: the file is opened with whatever application (if any)
 its extension is associated.
 
+When another \var{operation} is given, it must be a ``command verb''
+that specifies what should be done with the file.
+Common verbs documented by Microsoft are \code{'print'} and 
+\code{'edit'} (to be used on files) as well as \code{'explore'} and
+\code{'find'} (to be used on directories).
+
 \function{startfile()} returns as soon as the associated application
 is launched.  There is no option to wait for the application to close,
 and no way to retrieve the application's exit status.  The \var{path}
@@ -1646,6 +1654,7 @@ function doesn't work if it is.  Use the \function{os.path.normpath()}
 function to ensure that the path is properly encoded for Win32.
 Availability: Windows.
 \versionadded{2.0}
+\versionadded[The \var{operation} parameter]{2.5}
 \end{funcdesc}
 
 \begin{funcdesc}{system}{command}
index 619549d722cfac71b1edf9a9874a29d0b17e5fb3..9f92bf4595c44a8440c05146d785f15db66a12b2 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -218,6 +218,9 @@ Core and builtins
 Extension Modules
 -----------------
 
+- Patch #1393157: os.startfile() now has an optional argument to specify
+  a "command verb" to invoke on the file.
+
 - Bug #876637, prevent stack corruption when socket descriptor
   is larger than FD_SETSIZE.
 
index f35c0908089cf4599d4a082b9300940742d00cf8..bd5c32ad4e37df76909c9c92d6174696605f2cc3 100644 (file)
@@ -7385,11 +7385,15 @@ posix_abort(PyObject *self, PyObject *noargs)
 
 #ifdef MS_WINDOWS
 PyDoc_STRVAR(win32_startfile__doc__,
-"startfile(filepath) - Start a file with its associated application.\n\
+"startfile(filepath [, operation]) - Start a file with its associated\n\
+application.\n\
 \n\
-This acts like double-clicking the file in Explorer, or giving the file\n\
-name as an argument to the DOS \"start\" command:  the file is opened\n\
-with whatever application (if any) its extension is associated.\n\
+When \"operation\" is not specified or \"open\", this acts like\n\
+double-clicking the file in Explorer, or giving the file name as an\n\
+argument to the DOS \"start\" command: the file is opened with whatever\n\
+application (if any) its extension is associated.\n\
+When another \"operation\" is given, it specifies what should be done with\n\
+the file.  A typical operation is \"print\".\n\
 \n\
 startfile returns as soon as the associated application is launched.\n\
 There is no option to wait for the application to close, and no way\n\
@@ -7403,12 +7407,15 @@ static PyObject *
 win32_startfile(PyObject *self, PyObject *args)
 {
        char *filepath;
+       char *operation = NULL;
        HINSTANCE rc;
-       if (!PyArg_ParseTuple(args, "et:startfile", 
-                               Py_FileSystemDefaultEncoding, &filepath))
+       if (!PyArg_ParseTuple(args, "et|s:startfile", 
+                             Py_FileSystemDefaultEncoding, &filepath, 
+                             &operation))
                return NULL;
        Py_BEGIN_ALLOW_THREADS
-       rc = ShellExecute((HWND)0, NULL, filepath, NULL, NULL, SW_SHOWNORMAL);
+       rc = ShellExecute((HWND)0, operation, filepath, 
+                         NULL, NULL, SW_SHOWNORMAL);
        Py_END_ALLOW_THREADS
        if (rc <= (HINSTANCE)32) {
                PyObject *errval = win32_error("startfile", filepath);