简体   繁体   中英

"The command line is too long" with subprocess.run

I'm trying to execute the subprocess.run command.

I have a parameter that's very large - it's basically a SQL statement more than 10000 characters long.

Executing

subprocess.run(["cmd", param1, param2, param3, param4, param5, param6, param7, param8, param9], shell=True)

returns an error The command line is too long.

It seems the limit for total length of parameters is around 8000 chars.

Running python on Windows:

Python 3.10.8 (tags/v3.10.8:aaaf517, Oct 11 2022, 16:50:30) [MSC v.1933 64 bit (AMD64)] on win32

Is there a way to pass such parameter?

You can try something like this. Save your parameters into file (eg params.txt), then:

set /p PARAMS= < params.txt
cmd %PARAMS%

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM