I am currently trying to use the latest pysonar-scanner module (0.2.0.520) under Windows and Linux to scan a Poetry project. The scanner works fine under Linux but under windows the almost same scanner call leads to an Error.
I already verified that a bare sonar-scanner call works flawless on my Windows and Linux setup.
I am performing the following command under Linux and Windows in a basic manner:
pysonar-scanner -Dsonar.projectBaseDir=C:/MyPathToHomeDir -Dtoml.path=C:/MyPathToHomeDir/pyproject.toml -X
Under windows the following stack trace is printed:
Error during SonarScanner execution: [WinError 2] The system cannot find the file specified
Traceback (most recent call last):
File "C:\b01\_w\_temp\venv\Lib\site-packages\pysonar_scanner\__main__.py", line 31, in scan
env.scan()
File "C:\b01\_w\_temp\venv\Lib\site-packages\pysonar_scanner\environment.py", line 49, in scan
self.scanner().scan()
File "C:\b01\_w\_temp\venv\Lib\site-packages\pysonar_scanner\scanner.py", line 38, in scan
process = self.execute_command()
^^^^^^^^^^^^^^^^^^^^^^
File "C:\b01\_w\_temp\venv\Lib\site-packages\pysonar_scanner\scanner.py", line 54, in execute_command
return Popen(cmd, stdout=PIPE, stderr=PIPE)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\subprocess.py", line 1026, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Python311\Lib\subprocess.py", line 1538, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [WinError 2] The system cannot find the file specified
However if i “patch” the package itself by manipulating the scanner.py module inside the pip package, I can get it to work:
If in line 54 inside the execute_command method the block “shell=True” is added, the python module works flawlessly under windows and the error is gone.
The patched method looks like this:
def execute_command(self) -> Popen:
cmd = self.compute_command()
return Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True)
Will this behavior be patched in an upcoming release, would it help if i make a pull request with this patch? Maybe there is a better fix for this since the added parameter may also induce a greater security risk.