oconnor663 / duct.rs

a Rust library for running child processes
MIT License
795 stars 34 forks source link

Incorrect escaping on Windows #104

Closed patrikha closed 2 years ago

patrikha commented 2 years ago

Hi, I'm trying to write a bootstrapper for our proprietary buildsystem which relies a lot on python but I get into issues when trying the following (simplified python script to show the issue): cmd!(r"products\venv\Scripts\activate.bat", "&&", "python", "-c", "import sys; print(sys.version)")

then I get:

2022-04-05T05:03:34.251Z DEBUG [nspbuild::python] Verify Python virtual environment
  File "<string>", line 1
    "import
    ^
SyntaxError: unterminated string literal (detected at line 1)

The code works just fine on Linux (when changing the path to activate) Also same issue when using duct_sh::sh_dangerous, works in Linux but not Windows sh_dangerous("products\\venv\\Scripts\\activate.bat && python -c \"import sys; print(sys.version)\"")

Any suggestions on how to get the last string escaped correctly? Using version 0.13.5

oconnor663 commented 2 years ago

Hmm, I'm not sure what's going on, but one thing that jumps out at me is the && in your first example. That's a shell operator, but cmd! doesn't invoke the shell. So that operator and everything after it are getting passed as literal arguments to activate.bat, which doesn't seem like what you meant.

patrikha commented 2 years ago

Ok, makes sense then. Does duct support grabbing the environment after run? Activating a Python venv is basically just setting environment variables and if I could grab the env and then pass it to the next call to invoke Python that would be great.

oconnor663 commented 2 years ago

No duct doesn't have any way to extract a child's environment. But if you're trying to programmatically run Python programs inside a virtualenv, I think it might be cleaner to skip the activate script and do something like this: https://stackoverflow.com/a/48174818/823869

patrikha commented 2 years ago

OK clear and thanks for your quick response!