python subprocess.call error when pipe to file
Question: I am getting an usual error in python 3.4, when I'm calling a command, say
`net view` in the form of: `subprocess.call("net view")` returns `error code
0` (i.e. successful)

But when I do `subprocess.call("net view > targets.txt")` it returns `error
code 1` (unsuccessful).

Why does this error appear in python and is there a way to pipe output to file
in a similar way?


Answer: The easiest way to do what you want is to redirect `stdout` to a file object:

    
    
    from subprocess import check_call
    with open("targets.txt","w" ) as f:
        check_call(["net", "view"], stdout=f)
    

`check_call` will raise an error for `any non-zero` exit status.

