简体   繁体   English

OSError: [Errno 7] 参数列表太长:'php' - Python 3.6

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

I want to call PHP script from my Python script我想从我的 Python 脚本中调用 PHP 脚本

I have this code我有这个代码

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

but I am getting error但我收到错误

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

I have read online threads that I should always use subprocess.run for Python 3+我已经阅读了在线线程,我应该始终使用subprocess.run for Python 3+

I have also tried我也试过

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

But then I get但后来我得到

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

My string is 141,664 characters = 141,706 bytes and that can get larger too我的字符串是141,664 characters = 141,706 bytes并且也可以变大

What should I do?我该怎么办? How to surpass length error for my Python script?如何超过我的 Python 脚本的长度错误?

My uname -a output is我的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 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

Thanks to @Andras Deak for pointing me to right direction, solution was to to send and read data from STDIN instead of Command Line感谢@Andras Deak为我指明了正确的方向,解决方案是从 STDIN 而不是命令行发送和读取数据

WORKING SOLUTION工作解决方案

Python code Python代码

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

PHP code PHP代码

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

Old code (not working)旧代码(不起作用)

Python code Python代码

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

PHP code 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.

相关问题 Linux OS中的Python OSError no 7(参数列表太长) - Python OSError no 7 (Argument list too long ) in linux OSError:[Errno 7] ubuntu上的参数列表太长,python用popen调用bitcoind-cli - OSError: [Errno 7] Argument list too long on ubuntu, python calling bitcoind-cli with popen 间歇性“OSError: [Errno 7] Argument list too long”和短命令(~125 个字符) - Intermittent “OSError: [Errno 7] Argument list too long” with short command (~125 chars) 为什么我收到 OSError: [Errno 7] 参数列表太长:b'/usr/local/bin/git'? - Why I`m getting OSError: [Errno 7] Argument list too long: b'/usr/local/bin/git'? OSError:[Errno 63] JSON 文件(python)中的文件名太长 - OSError: [Errno 63] File name too long in JSON FILE (python) 为什么在使用mrjob v0.4.4时,[Errno 7]参数列表过长且OSError:[Errno 24]打开的文件太多? - Why am I getting [Errno 7] Argument list too long and OSError: [Errno 24] Too many open files when using mrjob v0.4.4? OSError:[Errno 36]文件名太长: - OSError: [Errno 36] File name too long: OSError: [Errno 63] 文件名太长 - OSError: [Errno 63] File name too long OSError:[Errno 36]使用Popen时文件名太长-Python - OSError: [Errno 36] File name too long while using Popen - Python Python Pandas OSError: [Errno 22] 无效参数: - Python Pandas OSError: [Errno 22] Invalid argument:
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM