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

  • Home
  • SEARCH
  • 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 9043499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:44:43+00:00 2026-06-16T10:44:43+00:00

So I am trying to store the output of a command into a variable.

  • 0

So I am trying to store the output of a command into a variable. I do not want it to display output while running the command though…

The code I have right now is as follows…

def getoutput(*args):
    myargs=args
    listargs=[l.split(' ',1) for l in myargs]
    import subprocess
    output=subprocess.Popen(listargs[0], shell=False ,stdout=subprocess.PIPE)   
    out, error = output.communicate()
    return(out,error)


def main():

    a,b=getoutput("httpd -S")

if __name__ == '__main__':
    main()

If I put this in a file and execute it on the command line. I get the following output even though I do not have a print statement in the code. How can I prevent this, while still storing the output?

#python ./apache.py 
httpd: Could not reliably determine the server's fully qualified domain name, using xxx.xxx.xxx.xx for ServerName
Syntax OK
  • 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-16T10:44:44+00:00Added an answer on June 16, 2026 at 10:44 am

    What you are seeing is standard-error output, not standard-output output. Stderr redirection is controlled by the stderr constructor argument. It defaults to None, which means no redirection occurs, which is why you see this output.

    Usually it’s a good idea to keep stderr output since it aids debugging and doesn’t affect normal redirection (e.g. | and > shell redirection won’t capture stderr by default). However you can redirect it somewhere else the same way you do stdout:

    sp = subprocess.Popen(listargs[0], shell=False,
        stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    output, error = sp.communicate()
    

    Or you can just drop stderr:

    devnull = open(os.devnull, 'wb') #python >= 2.4
    sp = subprocess.Popen(listargs[0], shell=False,
        stdout=subprocess.PIPE, stderr=devnull)
    
    #python 3.x:
    sp = subprocess.Popen(listargs[0], shell=False
        stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to store the output of the find command to an array. I
I'm trying to make a system call in Python and store the output to
I'm trying to store an image into an SQL database without using temporary files.
I'm trying to store a std::map on a shared memory segment. But I'm not
I'm trying to pipe the output of a command like this: some_command | ruby
I'm trying to store a DataTable into a single column in a SQL Server
I am trying to avoid creating any new files to store output in order
I'm trying to write a C program that grabs command output and then i'll
I'm trying to reformat the output of the last command e.g. last -adn 10
Possible Duplicate: Capturing multiple line output to a bash variable I have what is

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.