util.py function tmpfile does not work as intended on windows #13

syserr0r opened this Issue Dec 16, 2013 · 1 comment


2 participants

The function tmpfile creates a temp file with a code snippet to be linted and runs the linter command on the file, finally returning the result, however on windows the temp file cannot be read while it is still open.

Apologies in advance for my messy code, but here is a working replacement tmpfile function:

def tmpfile(cmd, code, suffix='', output_stream=STREAM_STDOUT):
    Return the result of running an executable against a temporary file containing code.

    It is assumed that the executable launched by cmd can take one more argument
    which is a filename to process.

    The result is a string combination of stdout and stderr.


    with tempfile.NamedTemporaryFile(suffix=suffix, delete=False) as f:
        if isinstance(code, str):
            code = code.encode('utf8')

        cmd = cmd + (f.name,)
        out = popen(cmd)
        if out:
            out = out.communicate()
            r = combine_output(out, output_stream)
            r = ''
    return r

PS: This was noticed primarily when trying to get the phplint linter working


This comment has been minimized.

Show comment Hide comment

aparajita Dec 17, 2013


Good catch. A fix has been pushed.


aparajita commented Dec 17, 2013

Good catch. A fix has been pushed.

@aparajita aparajita closed this Dec 17, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment