[Python-checkins] CVS: python/dist/src/Modules posixmodule.c,2.170,2.171

Tim Peters python-dev@python.org
Fri, 22 Sep 2000 03:05:57 -0700


Update of /cvsroot/python/python/dist/src/Modules
In directory slayer.i.sourceforge.net:/tmp/cvs-serv17199/python/dist/src/Modules

Modified Files:
	posixmodule.c 
Log Message:
Implemented new os.startfile function, unique to Windows, exposing a
subset of Win32 ShellExecute's functionality.  Guido wants this because
IDLE's Help -> Docs function currently crashes his machine because of a
conflict between his version of Norton AntiVirus (6.10.20) and MS's
_popen.  Docs for startfile are being mailed to Fred (or just read the
docstring -- it tells the whole story).
Changed webbrowser.py to use os.startfile instead of os.popen on Windows.
Changed IDLE's EditorWindow.py to pass an absolute path for the docs
(hardcoding ShellExecute's "directory" arg to "." as used to be done let
IDLE work, but made the startfile command exceedingly obscure for other
uses -- the MS docs are terrible, of course, & still not sure I
understand it).
Note that Windows Python must link with shell32.lib now!  That's where
ShellExecute lives.


Index: posixmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/posixmodule.c,v
retrieving revision 2.170
retrieving revision 2.171
diff -C2 -r2.170 -r2.171
*** posixmodule.c	2000/09/15 07:44:49	2.170
--- posixmodule.c	2000/09/22 10:05:53	2.171
***************
*** 5103,5106 ****
--- 5103,5138 ----
  }
  
+ #ifdef MS_WIN32
+ static char win32_startfile__doc__[] = "\
+ startfile(filepath) - Start a file with its associated 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\
+ \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\
+ to retrieve the application's exit status.\n\
+ \n\
+ The filepath is relative to the current directory.  If you want to use\n\
+ an absolute path, make sure the first character is not a slash (\"/\");\n\
+ the underlying Win32 ShellExecute function doesn't work if it is.";
+ 
+ static PyObject *
+ win32_startfile(PyObject *self, PyObject *args)
+ {
+ 	char *filepath;
+ 	HINSTANCE rc;
+ 	if (!PyArg_ParseTuple(args, "s:startfile", &filepath))
+ 		return NULL;
+ 	Py_BEGIN_ALLOW_THREADS
+ 	rc = ShellExecute((HWND)0, NULL, filepath, NULL, NULL, SW_SHOWNORMAL);
+ 	Py_END_ALLOW_THREADS
+ 	if (rc <= (HINSTANCE)32)
+ 		return win32_error("startfile", filepath);
+ 	Py_INCREF(Py_None);
+ 	return Py_None;
+ }
+ #endif
  
  static PyMethodDef posix_methods[] = {
***************
*** 5206,5209 ****
--- 5238,5242 ----
  	{"popen3",	win32_popen3, METH_VARARGS},
  	{"popen4",	win32_popen4, METH_VARARGS},
+ 	{"startfile",	win32_startfile, METH_VARARGS, win32_startfile__doc__},
  #endif
  #endif /* HAVE_POPEN */