0

The subprocess calls Diffutils which takes two files.

Diff.exe 1.txt 2.txt

And returns the differences between them.

The following code works...

process = subprocess.Popen(relativePath1 + 'diff.exe ' + relativePath + '/1.txt ' + relativePath + '/2.txt', cwd=relativePath1, stdout=subprocess.PIPE)
process.wait()
print(process.stdout.read().decode())

I'd like to replace relativePath + '/1.txt ' + relativePath + '/2.txt' with strings instead of file destinations.

I found this similar post Python string as file argument to subprocess which takes in one argument ... but could not get this to work passing two strings to replace the two paths requested by diff.exe.

One = 'bla bla bal bla'.encode()
Two = 'bla xxx bal bla'.encode()

p = subprocess.Popen([relativePath1 + 'diff.exe'], shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=[subprocess.PIPE, subprocess.PIPE])
p.communicate(input=One, Two)
Rhys
  • 4,926
  • 14
  • 41
  • 64
  • 1
    `diff`(`.exe`) requires two files as input: it can't diff two strings. What are you trying to do? –  Mar 10 '18 at 23:54
  • Perhaps the [difflib module](https://docs.python.org/3.6/library/difflib.html) can help you. –  Mar 10 '18 at 23:55
  • I had been suggested difflib here https://stackoverflow.com/questions/48737881/python-3-differences-between-two-strings ... and abandoned it here https://stackoverflow.com/questions/48859026/python3-difflib-sequencematcher ... diffutils accomplishes this task with less mental stress. Thanks for commenting! – Rhys Mar 11 '18 at 06:22
  • You are attempting to send two *strings* to an executable that takes two *filenames* as input; that is not the same. Why do you think that'll work? –  Mar 11 '18 at 07:59

0 Answers0