1

I am using this code to read a json file in subprocess. It does work for only small jsons, If it exceeds over 33766 count. it will show a error showing

FileNotFoundError: [WinError 206] The filename or extension is too long.

this is beccause of exceeding 33766 count. so how to read the json file using popen .Read that this can solve the problem. Help me with suggestions. I am new here :\

import subprocess
import json
import os

from pprint import pprint

auth = "authorization: token 1234

file = "jsoninput11.json"
fd=open("jsoninput11.json")
json_content = fd.read()
fd.close()


subprocess.run(["grpcurl", "-plaintext","-H", auth,"-d","@",json_content,"-format","json","100.20.20.1:5000","api.Service/Method"])

1 Answers1

0

I am not sure but maybe the problem is related to the bufsize (check this: Very large input and piping using subprocess.Popen ) Does it works with capture_output=False?

subprocess.run(["grpcurl", "-plaintext","-H", auth,"-d","@",json_content,"-format","json","100.20.20.1:5000","api.Service/Method"], capture_output=False)

On the other side, if you need the output you may need to deal with the PIPE of Popen.

Fabrizio
  • 927
  • 9
  • 20
  • same error. My json file has around 3000 lines . –  May 13 '19 at 10:16
  • I see, maybe you can try this, if it doesn't work then I cannot help, sorry. Remove the `capture_output=False`. Open a file: `f = open("blah.txt", "w")` then add in your "run" `stdout=f`. This will redirect the stdout to the file. – Fabrizio May 13 '19 at 12:01