簡體   English   中英

OSError: [Errno 7] 參數列表太長:'php' - Python 3.6

[英]OSError: [Errno 7] Argument list too long: 'php' - Python 3.6

我想從我的 Python 腳本中調用 PHP 腳本

我有這個代碼

subprocess.run(['php', "script.php", long_string], stdout=subprocess.PIPE)

但我收到錯誤

OSError: [Errno 7] Argument list too long: 'php'

我已經閱讀了在線線程,我應該始終使用subprocess.run for Python 3+

我也試過

subprocess.run(['ulimit', '-s', 'unlimited', 'php', "script.php", long_string], stdout=subprocess.PIPE, shell=True)

但后來我得到

OSError: [Errno 7] Argument list too long: '/bin/sh'

我的字符串是141,664 characters = 141,706 bytes並且也可以變大

我該怎么辦? 如何超過我的 Python 腳本的長度錯誤?

我的uname -a輸出是

Linux mani 2.6.32-042stab123.9 #1 SMP Thu Jun 29 13:01:59 MSK 2017 x86_64 x86_64 x86_64 GNU/Linux

感謝@Andras Deak為我指明了正確的方向,解決方案是從 STDIN 而不是命令行發送和讀取數據

工作解決方案

Python代碼

subprocess.run(['php', "script.php"], input=long_string.encode("utf-8"), stdout=subprocess.PIPE)

PHP代碼

//to receive data from our Python scrapers
if (defined('STDIN')) {
    $post = json_decode(fgets(STDIN), true);
} 

舊代碼(不起作用)

Python代碼

subprocess.run(['php', "script.php", long_string], stdout=subprocess.PIPE)

PHP代碼

//to receive data from our Python scrapers
if (defined('STDIN')) {
    $post = json_decode($argv[1], true);
} 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM