【问题标题】:python - subprocess length limitpython - 子进程长度限制
【发布时间】:2017-05-21 16:23:59
【问题描述】:

我必须通过 python 脚本调用创建一封电子邮件:

subprocess.call([
    'thunderbird',
    '-compose',
    "preselectid='{}',to='{}',cc='{}',subject='{}',body='{}'".format(
        preselectid, to, cc, subject, body),
    ])

但是当body“太大”时,电子邮件会被截断。

我知道在 Windows 上限制为 32,768 个字符 (What is the subprocess.Popen max length of the args parameter?),但我在 Linux 上(使用 zsh)并且在使用

回显字符串时
subprocess.call([
    'echo',
    "preselectid='{}',to='{}',cc='{}',subject='{}',body='{}'".format(
        preselectid, to, cc, subject, body),
    ])

我收到完整且正确的电子邮件内容。

我该如何解决这个问题?

编辑: 感谢@slezica,我发现复制粘贴生成的电子邮件并从命令行运行命令,无论如何,我得到了截断的电子邮件(在 32,303 字符处)。 问题是thunderbird

【问题讨论】:

  • 您遇到错误了吗?如果“thunderbird -compose”和“echo”之间的大小差异跨越某个界限,你能用echo 尝试更大的主体吗?
  • 尝试从命令行运行调用。这可能是thunderbird 的限制,或者您可能因为thunderbird -composeecho 之间的字符差异而达到了限制
  • @slezica 很好的提示(我很笨),我已经编辑了问题
  • 不是解决方案,但运行getconf ARG_MAX 可以获得shell 参数的最大长度。如果echo 可以接受,这可能只是thunderbird 的限制
  • @slezica:是的,我现在也认为问题出在雷鸟身上。 ARG_MAX 的大小为 2097152。

标签: python linux subprocess pipe thunderbird


【解决方案1】:

这是准答案。

在打开错误报告 (https://bugzilla.mozilla.org/show_bug.cgi?id=1329312) 后,我被告知 Thunderbird 的开发人员

implemented an option where you can read the message from a file with message=, see bug 882104. That will be shipping in TB 52, so you could use this now in Earlybird.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-06
    • 2015-03-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-21
    • 2018-10-02
    • 2013-10-25
    相关资源
    最近更新 更多