admin管理员组文章数量:1123935
In Python, is there a way to get the maximum number of characters that can be passed to a subprocess on the host in question?
I'm asking for implementing xargs-like functionality, i.e. running a command on a (potentially huge) list of file paths collected previously by python functions, so I'd need to know how many args/chars I can pass at a time without exceeding limits, and divide into multiple calls if necessary.
In Python, is there a way to get the maximum number of characters that can be passed to a subprocess on the host in question?
I'm asking for implementing xargs-like functionality, i.e. running a command on a (potentially huge) list of file paths collected previously by python functions, so I'd need to know how many args/chars I can pass at a time without exceeding limits, and divide into multiple calls if necessary.
Share Improve this question asked yesterday mara004mara004 2,31213 silver badges30 bronze badges1 Answer
Reset to default 1On Unix you can use
max_args = os.sysconf('SC_ARG_MAX')
to get the byte limit on the combined argument list and environment. This may include the null terminators at the end of each argument and environment variable.
So when determining how much space you have for arguments, you should subtract
env_size = sum(len(var)+1 for var in os.environ)
There's no equivalent on Windows, but typically the limit is 32,768 bytes.
本文标签: pythonGet char limit for subprocess argsStack Overflow
版权声明:本文标题:python - Get char limit for subprocess args - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736610584a1945432.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论