Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows] Alternate NT drive paths not handled in convert_dos_path #2494

Open
klightspeed opened this issue Jan 3, 2025 · 0 comments · May be fixed by #2495
Open

[Windows] Alternate NT drive paths not handled in convert_dos_path #2494

klightspeed opened this issue Jan 3, 2025 · 0 comments · May be fixed by #2495

Comments

@klightspeed
Copy link

Summary

  • OS: Windows 11
  • Architecture: 64-bit
  • Psutil version: 6.1.1
  • Python version: 3.13.1
  • Type: core

Description

convert_dos_path does not currently handle UNC paths or paths of the form \??\X: (as returned by Wine).
This results in the psutil/tests/test_process.py::TestProcess::test_exe test failing in the following cases:

  • Python is run from a network share; or
  • The tests are performed under Wine on a drive other than the one Python is installed on.

In the tests below, TestProcessPath is compiled from https://gist.github.com/klightspeed/cbb6b9957c521517673798bff4e15663

Case 1: Python is run from a network share:

D:\venv\psutil\psutil>net use Z: \\localhost\c$
The command completed successfully.


D:\venv\psutil\psutil>set PATH=Z:\Program Files\Python313\Scripts\;Z:\Program Files\Python313\;%PATH%

D:\venv\psutil\psutil>python -m pytest -v -s --tb=short psutil/tests/test_process.py::TestProcess::test_exe
============================= test session starts =============================
platform win32 -- Python 3.13.1, pytest-8.3.4, pluggy-1.5.0 -- Z:\Program Files\Python313\python.exe
cachedir: .pytest_cache
rootdir: D:\venv\psutil\psutil
configfile: pyproject.toml
plugins: xdist-3.6.1
collected 1 item

psutil/tests/test_process.py::TestProcess::test_exe FAILED

================================== FAILURES ===================================
____________________________ TestProcess.test_exe _____________________________
psutil\tests\test_process.py:741: in test_exe
    out = sh([exe, "-c", "import os; print('hey')"])
psutil\tests\__init__.py:335: in wrapper
    return fun(*args, **kwargs)
psutil\tests\__init__.py:498: in sh
    p = subprocess.Popen(cmd, **kwds)
Z:\Program Files\Python313\Lib\subprocess.py:1036: in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
Z:\Program Files\Python313\Lib\subprocess.py:1548: in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
E   FileNotFoundError: [WinError 2] The system cannot find the file specified
=========================== short test summary info ===========================
FAILED psutil/tests/test_process.py::TestProcess::test_exe - FileNotFoundError: [WinError 2] The system cannot find the file specified
============================== 1 failed in 2.24s ==============================

D:\venv\psutil\psutil>python -c "import os; import psutil; p = psutil.Process(os.getpid()); print(p.exe())"
\localhost\c$\Program Files\Python313\python.exe

D:\venv\psutil\psutil>net use Y: \\localhost\d$
The command completed successfully.


D:\venv\psutil\psutil>Y:\venv\TestProcessPath.exe
NtQuerySystemInformation(SystemProcessIdInformation) -> PID = 33004, Status = 00000000, ImageName = \Device\Mup\localhost\d$\venv\TestProcessPath.exe
QueryFullProcessImageNameW -> hProcess = FFFFFFFFFFFFFFFF, Success = 1, ImageName = \\localhost\d$\venv\TestProcessPath.exe

Case 2: tests are run under Wine on a different drive to that Python is installed from:

Z:\home\klightspeed\wine-psutil\psutil>python -m pytest -v -s --tb=short psutil/tests/test_process.py::TestProcess::test_exe
============================= test session starts =============================
platform win32 -- Python 3.11.9, pytest-8.3.4, pluggy-1.5.0 -- C:\Program Files\Python311-32\python.exe
cachedir: .pytest_cache
rootdir: Z:\home\klightspeed\wine-psutil\psutil
configfile: pyproject.toml
plugins: xdist-3.6.1
collected 1 item

psutil/tests/test_process.py::TestProcess::test_exe FAILED

================================== FAILURES ===================================
____________________________ TestProcess.test_exe _____________________________
C:\wine-psutil\psutil\psutil\tests\test_process.py:741: in test_exe
    out = sh([exe, "-c", "import os; print('hey')"])
psutil\tests\__init__.py:335: in wrapper
    return fun(*args, **kwargs)
psutil\tests\__init__.py:498: in sh
    p = subprocess.Popen(cmd, **kwds)
C:\Program Files\Python311-32\Lib\subprocess.py:1026: in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
C:\Program Files\Python311-32\Lib\subprocess.py:1538: in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
E   FileNotFoundError: [WinError 2] File not found
=========================== short test summary info ===========================
FAILED psutil/tests/test_process.py::TestProcess::test_exe - FileNotFoundError: [WinError 2] File not found
============================== 1 failed in 0.45s ==============================

Z:\home\klightspeed\wine-psutil\psutil>python -c "import os; import psutil; p = psutil.Process(os.getpid()); print(p.exe())"
\Program Files\Python311-32\python.exe

Z:\home\klightspeed\wine-psutil\psutil>..\TestProcessPath\TestProcessPath.exe
NtQuerySystemInformation(SystemProcessIdInformation) -> PID = 312, Status = 00000000, ImageName = \??\Z:\home\klightspeed\wine-psutil\TestProcessPath\TestProcessPath.exe
QueryFullProcessImageNameW -> hProcess = ffffffff, Success = 1, ImageName = Z:\home\klightspeed\wine-psutil\TestProcessPath\
TestProcessPath.exe

@klightspeed klightspeed added the bug label Jan 3, 2025
@klightspeed klightspeed linked a pull request Jan 3, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant