[Python] How to run yamllint command line using Python?

Discussão em 'Python' iniciado por Stack, Agosto 4, 2025.

  1. Stack

    Stack Membro Participativo

    I want to run yamllint(yaml_file) using subprocess module in Python. I know there is another module to call yamllint in Python, but I want to do it using subprocess.

    lint='yamllint("%s")'%(args.yaml)
    print(lint)

    p=subprocess.Popen(lint,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    stdoutdata,stderr=p.communicate()
    if stderr:
    print(stderr)
    print("Please check YAML format")
    quit()


    This gives me an error:

    b'/bin/sh: -c: line 0: syntax error near unexpected token `"delete.yaml"\'\n/bin/sh: -c: line 0: `yamllint("delete.yaml")\'\n'


    Please help me understand what is wrong in this.

    Continue reading...

Compartilhe esta Página