Python Forum
Popen - How can I read data before CTRL+C command is issued
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Popen - How can I read data before CTRL+C command is issued
#9
(Jun-27-2018, 05:59 AM)maffaz Wrote: Interesting! That is golden advice even if it does not work..

The ping example works fine with stdout but not the tool in question.

I am not at my computer until this evening and I will try it then but that is certainly something I have not tried as of yet!

I must stress that it is a windows CLI Tool but the beauty of subprocess is that it is cross platform.

Is there anything to consider if its windows?

Did you try to set stderr=subprocess.STDOUT? Some apps send output to stderr - don't ask me why, but I saw it happening, especially with HW-oriented apps.

One more thing I have forgotten (I haven't used subprocess for several months) - by default its output is bytestrings, universal_newlines=True forces its output to unicode strings.

If you run your command in terminal, does it provide continuous output - or only after you stop it? In the former case, my approach should work
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply


Messages In This Thread
RE: Popen - How can I read data before CTRL+C command is issued - by volcano63 - Jun-27-2018, 07:39 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with to check an Input list data with a data read from an external source sacharyya 3 486 Mar-09-2024, 12:33 PM
Last Post: Pedroski55
  Correctly read a malformed CSV file data klllmmm 2 2,059 Jan-25-2023, 04:12 PM
Last Post: klllmmm
  Read nested data from JSON - Getting an error marlonbown 5 1,442 Nov-23-2022, 03:51 PM
Last Post: snippsat
  Read data via bluetooth frohr 9 3,526 Jul-10-2022, 09:51 AM
Last Post: frohr
  Write and read back data Aggie64 6 1,947 Apr-18-2022, 03:23 PM
Last Post: bowlofred
  How to read rainfall time series and insert missing data points MadsM 4 2,235 Jan-06-2022, 10:39 AM
Last Post: amdi40
  Python continues after CTRL-C kjbolhuis 2 1,928 Aug-06-2021, 04:28 PM
Last Post: kjbolhuis
  [Solved] Using readlines to read data file and sum columns Laplace12 4 3,630 Jun-16-2021, 12:46 PM
Last Post: Laplace12
  Looping to read data in database CEC68 1 1,752 Sep-24-2020, 08:54 PM
Last Post: scidam
  Assigning data read from CSV to class faruk61 2 2,163 Apr-15-2020, 05:52 PM
Last Post: buran

Forum Jump:

User Panel Messages

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