0

I have tried many tactics to reorganize the output received from my query, but I'm unable to format the output being received back. I'm currently trying to compare two files using the "diff" command, but It sends all of the differences back mushed together. I have tried to reformat it by making it "diff -w", but Popen seems to not recognize the two commands together. Basically I'm trying to compare two Linux files and be able to format the output coming back so the user can easily look at what changes are being made.

#!/usr/bin/env python3
import subprocess

if(input("If you're happy with the changes say yes:") == "yes"):

    test = subprocess.Popen(['diff','-w','/file1','/file2'],stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
    output =  test.communicate()[0]
    print(output)
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
student_123
  • 47
  • 1
  • 5
  • Define 'mushed together'? There isn't anything special about running a command with `subprocess`; you get your results exactly as `diff` outputs them. – Martijn Pieters Sep 02 '16 at 21:28

1 Answers1

0

You need set universal_newlines=True in Popen constructor.

Aleksey Bakin
  • 1,506
  • 13
  • 27