Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8915819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:04:40+00:00 2026-06-15T05:04:40+00:00

I am using subprocess to run a command (from a spawned daemon) and trying

  • 0

I am using subprocess to run a command (from a spawned daemon) and trying to write results to a file. The resulting string from Popen is bytestring. How do I format this into something human readable before writing to a file? using python3.2

have tried:

print (x,file=o)
f.write(str(rc.so))
print (str(rc.so) + "\n")

Nothing ends up looking readable ..

suspect code:

  rc = subprocess.Popen([cmd], shell=True, stdout=subprocess.PIPE,   stderr=subprocess.PIPE)
  x = rc.stdout.readlines()
  rc.so, rc.se = rc.communicate()
  with open(of,'w') as o, open(ef,'w') as e:
     print (str(rc.so) + "\n",file=o)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T05:04:42+00:00Added an answer on June 15, 2026 at 5:04 am

    you need to decode it:

    my_byte_string.decode('utf-8')
    

    utf-8 might not be the best choice of decoding for your situation, it is one of a number of options available.

    so that print statement should be more like:

    print (rc.so.decode('utf-8') + "\n",file=o)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to run grep command from my Python module using the subprocess
How can I run the following command using subprocess.Popen ? mysqldump database_name table_name |
I'm trying to call an ImageMagick command from Python 2.7 using subprocess.call. My problem
I'm using Python subprocess to run a command on a remote server: p=subprocess.Popen('ssh blah@foo.com
I am using the subprocess module to run a find & grep command with
I am using using os.system call from python to run jar file. The jar
I'm trying to run a shell command from within a python script which needs
I want to run a command in pythong , using the subprocess module, and
On Linux, I'm using supbprocess.Popen to run an app. The command line of that
I'm trying to run console commands via subprocess.Popen , and whenever I run it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.