[英]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 而不是命令行发送和读取数据
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);
}
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.