I have the following python3 code to print difference of two files/directories:
def out_diff(arg1, arg2):
out = subprocess.Popen(['diff', '-r', arg1, arg2],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
stdout, stderr = out.communicate()
print(type(stdout))
print(type(stderr))
if len(stdout) != 0:
print('stdout: ', arg1, arg2, stdout.decode()), # error line
if stderr is not None:
print('stderr: ', arg1, arg2, stderr)
print('end of function')
out_diff('output1', 'output2')
And its output is the following:
stdout: output1 output2 diff: output1: No such file or directory
diff: output2: No such file or directory
end of function
My question is, whether or not I put a trailing comma on the stdout printing line (marked by "#"), an empty line is always printed. I don't understand why that is happening. Something should have changed based on the presence of the trailing comma.
My expectation was that since a '\n'
was in the stdout string, then if I did NOT put a trailing comma then 2 empty lines would be printed.