Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
546 views
in Technique[技术] by (71.8m points)

json - Subprocess module showing WindowsError in Python 2.7

I am writing an automation script in Python 2.7 and executing the pretty format command and trying to PIPE it into subprocess so that I can parse the data and directly input into a json file. I am executing the git log --pretty format command from the shell within the current folder of the project. I am using the jsonstream.Stream to parse the data and create a legal json file out of the array generated by the pretty format command. But I am getting an error on the stdout=subprocess.PIPE part of the code and the error states WindowsError: [Error 2] The system cannot find the file specified.

import jsonstreams
import subprocess

branch_name = 'man/ashish_c/robotics'
days = '30'
json_output = 'robotics_infra.json'

with subprocess.Popen(['git log', branch_name, '--since="' + log_length + 'days ago"', '--pretty=format:%h%p%an%s%b'], stdout=subprocess.PIPE) as input:
    with jsonstreams.Stream(jsonstreams.Type.array, filename=json_output) as output:
        while True:
            line = input.stdout.readline()
            if not line:
                break
            record = line.decode("utf-8").split("")
            with output.subobject() as output_e:
                output_e.write('commit', record[0])
                output_e.write('merge', record[1])
                output_e.write('author', record[2])
                output_e.write('title', record[3])
                output_e.write('body', record[4])

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
...