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
tools/pyboard: Run exec: command as a string. #3970
Conversation
The Python documentation recommends to pass the command as a string when using Popen(..., shell=True). https://docs.python.org/3.5/library/subprocess.html#subprocess.Popen
Can you provide a reproducible case that gave this issue? It would be good to understand what the issue is/was and why this is the right fix. This is a subtle change that may break other things. |
The way I can reproduce it is with this command, which runs the binary for the PCA10028 in my emulator. The first argument is the firmware binary as compiled with
I once tried printing all arguments it receives and it receives none without this PR, thus complaining about a missing argument. I also tried passing the unix Are there other places where |
Here is a better way to reproduce the error (aborted because it hangs):
You can see repro.py only gets a single argument, not all three as expected. This is the relevant line in the Python source: https://github.com/python/cpython/blob/3.5/Lib/subprocess.py#L1176 So the executed command (in the repro above) will be something like |
exec: and execpty: support was introduced to allow to communicate with QEMU, as prompted by Zephyr port: 647e72c . In the end, it was found that Zephyr's QEMU works "better" using execpty:, and that's what can be grepped in the codebase. The change introduced by this patch looks right, especially if backed by that quotation from the docs. But please be ready to test such changes against a well-known kind of tool (like QEMU), not just your own. |
Thanks @aykevl for the additional info. I could reproduce the problem.
Yes, that's the crux of the issue, that when passed as a list, the additional arguments (foo and bar above) are passed to the shell, not to the executing program. I tested also with the zephyr port, changing pyboard.py to use Merged in 0d7a088 with some additional comments in the commit message. |
The Python documentation recommends to pass the command as a string when using Popen(..., shell=True).
https://docs.python.org/3.5/library/subprocess.html#subprocess.Popen
I noticed this problem because I tried running tests with
exec:cmd...
and I passed some arguments (which somehow didn't end up in the argv of the called process without this change).