Python Forum
Popen does not show part of the data
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Popen does not show part of the data
#1
Hi! It's my code
ommand_line = 'git log --oneline'
process = subprocess.Popen(command_line, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output = process.communicate()[0].decode("utf-8")
print(output )
I expect to see for example
Output:
6934123 (HEAD -> master, tag: v1.5, origin/master, origin/HEAD) no message e839345 (tag: v1.4) no message 717c567 e f7c8543 merge
But I see
Output:
6934123 no message e839345 no message 717c567 e f7c8543 merge
Can i get first result?
Reply
#2
Popen.communicate() doesn't modify stdout in any way, it just pipes it to you. So either the command you're running is different from how you got the first output, OR some of that output wasn't in stdout, and was actually in stderr. Have you checked to see if stderr has any content?
Reply
#3
(Jan-31-2019, 08:31 PM)nilamo Wrote: Popen.communicate() doesn't modify stdout in any way, it just pipes it to you. So either the command you're running is different from how you got the first output, OR some of that output wasn't in stdout, and was actually in stderr. Have you checked to see if stderr has any content?

I input same command in windows console and get first result.
errs - empty
Reply
#4
Popen.communicate() returns two objects, stdout and stderr. You're ignoring stderr right now. Could you print both out, and show us the output?
Reply
#5
Example using new run() and parameter capture_output=True.
I give me correct output,it's also better/safer to use a list then is shell=False(default).
import subprocess

out = subprocess.run(['git', 'log', '--oneline'], capture_output=True)
print(out.stdout.decode())
Reply
#6
(Jan-31-2019, 09:51 PM)nilamo Wrote: Popen.communicate() returns two objects, stdout and stderr. You're ignoring stderr right now. Could you print both out, and show us the output?

[Image: OOMD7kTx9uk.jpg]

Expected result
[Image: gHXtweCUjgM.jpg]


(Feb-01-2019, 02:35 AM)snippsat Wrote: Example using new run() and parameter capture_output=True.
I give me correct output,it's also better/safer to use a list then is shell=False(default).
import subprocess

out = subprocess.run(['git', 'log', '--oneline'], capture_output=True)
print(out.stdout.decode())

Thx, I tried but get same output
Reply
#7
Try running from command line and not editor.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  PIL Image im.show() no show! Pedroski55 2 972 Sep-12-2022, 10:19 PM
Last Post: Pedroski55
  PIL Image im.show() no show! Pedroski55 6 4,936 Feb-08-2022, 06:32 AM
Last Post: Pedroski55
  show and storage real temperature data Arduino in Python3 linkxxx 0 1,856 Aug-21-2019, 04:07 PM
Last Post: linkxxx
  subprocess.Popen for lively data reading? Skaperen 4 3,464 Jul-04-2018, 01:20 AM
Last Post: Skaperen
  Popen - How can I read data before CTRL+C command is issued maffaz 13 10,298 Jun-28-2018, 09:18 AM
Last Post: maffaz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020