Comments (3)
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.
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.
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)
- Test ubelt/util_platform.py::find_exe:0 fails if which(1) is not installed HOT 5
- Investigate code scanning alert - is this a real vulnerability? HOT 1
- 23 errors in tests HOT 5
- pathlib is missing in requirements/tests.txt HOT 5
- 1.2.3: The test_deprecated_grabdata_args test fails HOT 3
- help to confirm the depends of the module HOT 2
- Provide a subprocess-compatible interface in cmd HOT 3
- test_numpy_object_array fails: TypeError: directly hashing ndarrays with dtype=object is unstable HOT 1
- import_module_from_name:0 test failure with Python 3.13.0b1 HOT 4
- Support for xxh3 HOT 1
- Sphinx documentation incorrect formatting. HOT 1
- Undefined name 'xdoc' in ubelt/util_colors.py HOT 1
- `pip install ubelt` incorrectly installs jaraco on linux HOT 2
- ub.argval strips equals signs ("=") from the value HOT 1
- Error in documentation for ubelt.util_dict.map_vals HOT 1
- Request: ensure director verbose mentions if it created a new directory HOT 1
- Docs are not being built right HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ubelt.