通过Gradle运行MLCP出现CreateProcess error=206报错咨询
问题根因
这个报错和MLCP的query_filter参数本身的大小限制无关,是Windows系统的进程命令行长度上限触发的错误:
Windows系统对创建进程时传入的总命令行长度有硬限制,Windows 10 1607版本之前上限为8191字符,后续版本虽有所放宽但仍然存在阈值。你将398行的JSON查询内容直接作为命令行参数传递给MLCP进程时,总命令行长度超过了系统上限,就会抛出CreateProcess error=206, The filename or extension is too long的异常。
最优解决方案
MLCP原生提供了查询文件参数,避免大查询内容占用命令行长度:
将原来直接给query_filter赋值JSON字符串的逻辑,改为先把变量替换后的JSON内容写入临时文件,再用query_filter_file参数指定该临时文件的路径即可,无需转义JSON内的双引号,也完全不会触发命令行长度限制。
修改后的Gradle任务核心代码参考:
def importDirs = new File("./teams").listFiles() importDirs.each { importDir -> def queries = importDir.listFiles() queries.each { file -> def taskname = importDir.name + "_" +file.name.replace('.json', '') task "copy_$taskname" ( type: com.marklogic.gradle.task.MlcpTask, group: 'abc', dependsOn: []) { classpath = configurations.mlcp command = 'COPY' input_database = mlAppConfig.contentDatabaseName input_host = inputHost input_port = port input_username = inputUsername input_password = inputPassword output_database = mlAppConfig.contentDatabaseName output_host = outputHost output_port = port output_username = outputUsername output_password = outputPassword // 新增:生成临时查询文件 def tempQueryFile = new File(buildDir, "temp_query_${taskname}.json") tempQueryFile.text = file.text.replaceAll('%%now%%', now).replaceAll('%%targetDate%%', targetDate) // 替换原来的query_filter配置 query_filter_file = tempQueryFile.absolutePath // 可选:任务执行结束后自动清理临时文件 doLast { if(tempQueryFile.exists()) tempQueryFile.delete() } max_split_size = 500 } } }
临时替代方案
如果仅超出长度不多,也可以先压缩JSON内容再赋值给query_filter:把JSON的所有换行、缩进空格全部删除,生成无冗余的单行JSON字符串,能缩短50%以上的命令行占用长度。但该方案仅为临时兼容,查询内容继续增长仍会触发长度限制。
内容的提问来源于stack exchange,提问作者ravvi
相关产品推荐
相关产品推荐

