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

Make subprocess.run(cmd, shell=True) call shell #180

Open
certik opened this issue Oct 16, 2024 · 2 comments
Open

Make subprocess.run(cmd, shell=True) call shell #180

certik opened this issue Oct 16, 2024 · 2 comments

Comments

@certik
Copy link
Collaborator

certik commented Oct 16, 2024

I want to replace this code:

import subprocess as sp

def run_cmd(cmd, cwd=None):
    print(f"+ {cmd}")
    process = sp.run(cmd, shell=True, cwd=cwd)
    if process.returncode != 0:
        print("Command failed.")
        exit(1)

with an equivalent code that however calls shell to execute the above command, not cmd.exe. Currently I get:

~/repos/lfortran/integration_tests$ python run_tests.py
+ rm -rf C:\Users\ondrejcertik\repos\lfortran\integration_tests/test-llvm
'rm' is not recognized as an internal or external command,
operable program or batch file.
Command failed.

What's the best way to do that?

@Hofer-Julian
Copy link
Contributor

Maybe this?

import subprocess as sp

def run_cmd(cmd, cwd=None):
    print(f"+ {cmd}")
    process = sp.run(["shell", "-c", cmd], cwd=cwd)
    if process.returncode != 0:
        print("Command failed.")
        exit(1)

@certik
Copy link
Collaborator Author

certik commented Oct 16, 2024

Yes, that's what I would like --- but we need to implement -c first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants