php - exec、system 和 shell_exec PHP 函数中的命令字符串不能超过 8175 个字符

标签 php windows shell

我遇到一个问题,我需要在 PHP 中编写冗长的命令并执行它们。但是,当命令长度超过8175个字符时,将无法执行。有趣的是,如果我手动将相同的命令复制并粘贴到终端中,它运行时不会出现任何问题。这是一个说明该问题的基本示例:

$longCommand = "echo ".str_repeat("a",8171); // longCommand length = 8176 -> fails
exec($longCommand, $output);
print_r($output);

如果将 $longCommand 字符串减少到 8175 个字符,则它会成功执行。从 PHP 执行命令时是否有字符限制?如果有,如何增加或绕过此限制?

最佳答案

刚刚发现这是 Windows 的官方记录限制:

The maximum length of the string that you can use at the command prompt is 8191 characters. This limitation applies to: the command line individual environment variables that are inherited by other processes, such as the PATH variable all environment variable expansions If you use Command Prompt to run batch files, this limitation also applies to batch file processing.

Source

关于php - exec、system 和 shell_exec PHP 函数中的命令字符串不能超过 8175 个字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77258270/

相关文章:

c# - 从 C# Windows 窗体调用 PHP Web 服务

php - 在单个查询中创建和插入

windows - 带有创建时间和最后修改时间的目录命令

windows - SVN:将本地更改合并到其他工作副本

linux - SeD 正则表达式替换

C Shell 打开文件并返回命令提示符

linux - 仅当非零时才在 bash 提示符中显示作业计数

php - mysql将十进制时间转换为xx :xx format

php - 调用从 for 循环创建的数组元素

windows - 使用 Windows 上的 docker 卷(仅在 docker 容器内)或使用主机操作系统安装/共享卷的读/写性能更好?