Giter VIP home page Giter VIP logo

Comments (3)

Erotemic avatar Erotemic commented on September 15, 2024

The idea is that ubelt shouldn't be manipulating the inputs unless it needs to. I want to support the ability to execute a command via either a str or a List[str], regardless of the value of shell, so it is easy for the user to turn that flag on / off without modifying the other inputs. That means when shell=True and the command is a List[str] I have to convert it to a single str, and when it is a str and shell=False, I have to break it up into a List[str] to conform to the Popen API.

Note that it does build the str variant in both cases for logging purposes, but if shell=True that should be exactly the imputed command with no modification, and when shell=False it doesn't use it for any execution.

However, it does look like this is broken on windows. This might simply be a matter of removing the windows check on the line if shell or sys.platform.startswith('win32'):. I'm not exactly sure why this is the case, it might just be a bug. I made a PR #140 that removes it, so I suppose we will see if the dashboards break.

If you could test that patch on your end and verify that it fixes the issue that would be very helpful. I think this is just an oversight on my part because I don't use windows often.

from ubelt.

Erotemic avatar Erotemic commented on September 15, 2024

It looks like the naive fix does break existing tests which submit commands like:

    py_script = ub.codeblock(
        r'''
        {pyexe} -c "
        while True:
            pass
        "
        ''').lstrip().format(pyexe=PYEXE)

and:

'{pyexe} -c "for i in range(10): print(str(i))"'.format(pyexe=PYEXE)

as the command to ubelt.cmd.

So it seems like Popen on windows accepts a regular string even when shell=False? That looks like the reason I had the check in there in the first place. I also have a reference to https://stackoverflow.com/questions/33560364/python-windows-parsing-command-lines-with-shlex nearby the area of interest, which is reminding me that it was tricky to try and get ubelt.cmd to parse a str input into a valid List[str] that could be sent to Popen. Do you have a recommendation for how to do that robustly, or an explanation for why it's not possible in general?

One of my original goals with ubelt.cmd was to make it trivial to copy commands from a script into a Python program and have them "just work". So I'd really like to support the case where it parses input into an appropriate input for Popen in the case where shell=False that works on windows and linux, especially when that command is just running a python -c ... script, which is ideally cross platform.

from ubelt.

Erotemic avatar Erotemic commented on September 15, 2024

Looking more at this is seems like SO#33560364 is saying on windows Popen can be a str even when shell=False. If that is true then we can just set args to the string and ignore building command_tup if shell=False and it is None on windows. Testing that now.

from ubelt.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.