pythonwindowssubprocess

"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?


Solution

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

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