RE: Obtaining hte currently running script under windows



On Behalf Of Sean Farrow
Is there any way to obtain the full path to the currently
running script under win32?
I am using the pythonw.exe file is that helps.
Sean.

Current working directory is not always reliable. There is a __file__
variable set if python.exe runs your script.

import os
import sys

module_name = os.path.dirname(unicode(__file__, sys.getfilesystemencoding(
)))

If your script is frozen via py2exe, you can use the sys.executable value to
get the module directory.

import os
import sys

module_name = os.path.dirname(unicode(sys.executable,
sys.getfilesystemencoding( )))

(You need the Unicode stuff if your path may include non-ASCII characters)

function module_path() in the alternate solution at
http://www.py2exe.org/index.cgi/WhereAmI will give you the module
(script/executable) directory whether your script is running normally or
frozen.

Regards,
Ryan

--
Ryan Ginstrom
translation@xxxxxxxxxxxx
http://ginstrom.com/

.



Relevant Pages

  • Re: Only boots in to AD recovery
    ... Good news found the root DC and will be running script on it. ... Dim oRoot, sConfigNamingContext, oADOConnection, oADOCommand, sADOQuery ...
    (microsoft.public.windows.server.active_directory)
  • Re: Creating SQL script to upgrade database
    ... but I am not running script through query ... I am running this script through windows ... installer program, which rollsback the installation of my application in case ... If you do select DROP objects option, ...
    (microsoft.public.sqlserver.tools)
  • Re: 2.4->2.5 current directory change?
    ... related to Windows behavior. ... appears to be the base directory of the running script. ... That means if you run a Python script located in another directory, ...
    (comp.lang.python)
  • RE: how to find ADC and DC
    ... running script little difficult for me. ... Muneer ... "ptwilliams" wrote: ...
    (microsoft.public.windows.server.active_directory)
  • Re: Overwrite a running script and restart?
    ... the update script to be able to update the wrapper itself. ... Can I safely overwrite the running script? ...
    (comp.unix.shell)