views:

12

answers:

1

I have a subprocess using communicate to get the output ans saving it to my database:

  p = Popen([str(pre_sync), '-avu', str(src), str(dest)], stdout=PIPE)
  syncoutput = p.communicate()
  check.log = syncoutput

It all works fine, but the output from communicate looks like this:

('sending incremental file list\n\nsent 89 bytes  received 13 bytes  204.00 bytes/sec\ntotal size is 25  speedup is 0.25\n', None)

All in a single line and with the "\n" inserted. Is there a way I can make it print each line in a new line? Thanks in advance.

+2  A: 
syncoutput,sync_error = p.communicate()
print(syncoutput)

p.communicate() returns a 2-tuple, composed of the output from stdout and stderr. When you print the 2-tuple, you see the \n characters. When you print the string (of the new syncoutput), you will get formatted text.

unutbu
Absolutely right! Thanks!
dura
@dura, be sure to **accept** this answer (check on the checkmark-shaped icon to the A's left) -- "thanks are cheap, but accepts matter" is part of SO's basic etiquette!-)
Alex Martelli