Python Forum
decoding sub.process output with multiple \n?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
decoding sub.process output with multiple \n?
#1
Hi, I have created a script using sub.process then after reading I got this output (not in order) and \n new line exist on the output. How can we fix this, tried striping or decoding but I'm having typeerror issue or decode not supported issue.

Example of the output:
b'interface HundredGigE0/2/0/0\n description CUSTOMER;AS222;6521;T326;10Mb;ORr23;GE CUstomer;ID;location;system;Man;time;new;\n load-interval 30\n flow ipv4 monitor NETFLOW_MONITOR sampler NETFLOW_SAMPLER ingress\n

Seem like the \n newline doesnt work?

Still searching how to decode this. Thanks
Reply
#2
what exactly do you try and not work? What do you want to get?
>>> output=b'interface HundredGigE0/2/0/0\n description CUSTOMER;AS222;6521;T326;10Mb;ORr23;GE CUstomer;ID;location;system;Man;time;new;\n load-interval 30\n flow ipv4 monitor NETFLOW_MONITOR sampler NETFLOW_SAMPLER ingress\n'
>>> output.decode()
'interface HundredGigE0/2/0/0\n description CUSTOMER;AS222;6521;T326;10Mb;ORr23;GE CUstomer;ID;location;system;Man;time;new;\n load-interval 30\n flow ipv4 monitor NETFLOW_MONITOR sampler NETFLOW_SAMPLER ingress\n'
>>> print(output.decode())
interface HundredGigE0/2/0/0
 description CUSTOMER;AS222;6521;T326;10Mb;ORr23;GE CUstomer;ID;location;system;Man;time;new;
 load-interval 30
 flow ipv4 monitor NETFLOW_MONITOR sampler NETFLOW_SAMPLER ingress

>>> 
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
@buran, Thanks it worked! :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  geojson to json --missing multiple row output yoshi 9 1,318 Mar-06-2022, 08:34 PM
Last Post: snippsat
  Run multiple process using subprocess Shiri 3 1,689 Nov-28-2021, 10:58 AM
Last Post: ghoul
  Process multiple pdf files Spartan314 1 867 Oct-27-2021, 10:46 PM
Last Post: Larz60+
  flask app decoding problem mesbah 0 1,466 Aug-01-2021, 08:32 PM
Last Post: mesbah
  Decoding a serial stream AKGentile1963 7 4,860 Mar-20-2021, 08:07 PM
Last Post: deanhystad
  Defining multiple functions in the same def process sparkt 5 1,798 Aug-09-2020, 06:19 PM
Last Post: sparkt
  xml decoding failure(bs4) roughstroke 1 1,502 May-09-2020, 04:37 PM
Last Post: snippsat
  python3 decoding problem but python2 OK mesbah 0 1,336 Nov-30-2019, 04:42 PM
Last Post: mesbah
  How to sharing object between multiple process from main process using Pipe Subrata 1 3,004 Sep-03-2019, 09:49 PM
Last Post: woooee
  utf-8 decoding failed every time i try adnanahsan 21 7,427 Aug-27-2019, 04:25 PM
Last Post: adnanahsan

Forum Jump:

User Panel Messages

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