'Python subprocess not running mvn commands on bash [duplicate]

So, I have the following subprocess that I want to run. Bear in mind that it is the first time I am doing something like this and therefore, I do not know how to run it. This is the file I am trying to run:

if __name__ == '__main__':
    os.chdir('pom_files')
    mypath = '.'
    onlyfiles = [f for f in os.listdir(mypath) if isfile(join(mypath, f))]
    for file in onlyfiles:
        m = re.search(r'(\w+)-(\d*\.\d*\.\d*)\.pom', file)
        package = m.group(1)
        version = m.group(2)
        shutil.copy(file, "pom.xml")
        effective_command = f"mvn help:effective-pom -Doutput='effective-pom-{package}-{version}.xml'"
        subprocess.run([effective_command])

What it does (or at least I assume so because I cant run it) is given a folder with pom files, it generates effective pom files for each of them. I use Windows, but after trying for a while to run it, I could not figure it out and installed wsl. I installed python with pip and venv, and also maven. I'll also attach a screenshot of my project as it might be useful for understanding.

My project's tree

This is the error I get when I try to run it:

(.venv) denis@DESKTOP-IKF3NT2:/mnt/c/Users/denis/PycharmProjects/pythonProject$ python main.py
Traceback (most recent call last):
  File "main.py", line 31, in <module>
    subprocess.run([effective_command])
  File "/usr/lib/python3.8/subprocess.py", line 493, in run
    with Popen(*popenargs, **kwargs) as process:
  File "/usr/lib/python3.8/subprocess.py", line 858, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.8/subprocess.py", line 1704, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: "mvn help:effective-pom -Doutput='effective-pom-junit-3.8.1.xml'"

If I write a simple command instead of my mvn command, such like "ls", when I call the file, it runs with no problems.

How can I run this mvn command?



Solution 1:[1]

I just figured this out right now, I needed to put also shell=True in the subprocess.run()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Denxah129