https://github.com/mhammond/pywin32/blob/main/win32/Demos/service/nativePipeTestService.py is a demo of using a service using python.exe and supports specifying the command-line, so that might be an option?

Mark

On 2023-06-01 5:28 a.m., Gualtiero Scotti wrote:
Hi, I need to start my python application through windows service. For this purpose I use pywin32.
I'm not able to make a Python instance to evaluate the -X uf8 flag.

This flag must be passed during python invocation only and not when it is already started. After some investigations I've found the service launch *pythonservice.exe* wrapper but I don't know how to pass the flag to the Python interpreter.

Is there another option to set this flag? It is possible to set an env variable *PYTHONUTF8=1 * but pythonservice.exe doesn't seem to evaluate it...
*
*
*My environment*
*- Windows 11 Home 22H2*
*- Python 3.11.1* (tags/v3.11.1:a7a450f, Dec  6 2022, 19:43:28) [MSC v.1934 32 bit (Intel)] on win32
- *Pywin32 305*
- *Pywin32-ctypes 0.2.0*

*Python documentation*


    4.7. UTF-8 mode¶
    <https://docs.python.org/3/using/windows.html#utf-8-mode>

New in version 3.7.

Windows still uses legacy encodings for the system encoding (the ANSI Code Page). Python uses it for the default encoding of text files (e.g. |locale.getencoding()| <https://docs.python.org/3/library/locale.html#locale.getencoding>).

This may cause issues because UTF-8 is widely used on the internet and most Unix systems, including WSL (Windows Subsystem for Linux).

You can use the Python UTF-8 Mode <https://docs.python.org/3/library/os.html#utf8-mode> to change the default text encoding to UTF-8. You can enable the Python UTF-8 Mode <https://docs.python.org/3/library/os.html#utf8-mode> via the |-X utf8| command line option, or the |PYTHONUTF8=1| environment variable. See |PYTHONUTF8| <https://docs.python.org/3/using/cmdline.html#envvar-PYTHONUTF8> for enabling UTF-8 mode, and Excursus: Setting environment variables <https://docs.python.org/3/using/windows.html#setting-envvars> for how to modify environment variables.

When the Python UTF-8 Mode <https://docs.python.org/3/library/os.html#utf8-mode> is enabled, you can still use the system encoding (the ANSI Code Page) via the “mbcs” codec.

Note that adding |PYTHONUTF8=1| to the default environment variables will affect all Python 3.7+ applications on your system. If you have any Python 3.7+ applications which rely on the legacy system encoding, it is recommended to set the environment variable temporarily or use the |-X utf8| command line option.

Note

Even when UTF-8 mode is disabled, Python uses UTF-8 by default on Windows for:

 *

    Console I/O including standard I/O (see *PEP 528*
    <https://peps.python.org/pep-0528/> for details).

 *

    The filesystem encoding
    
<https://docs.python.org/3/glossary.html#term-filesystem-encoding-and-error-handler>
 (see
    *PEP 529* <https://peps.python.org/pep-0529/> for details).

from -> https://docs.python.org/3/using/windows.html

Please help me!
Thanks in advance
*
*

_______________________________________________
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32
_______________________________________________
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32

Reply via email to