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 7009161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:49:40+00:00 2026-05-27T21:49:40+00:00

I need to store the result of a shell command that I executed in

  • 0

I need to store the result of a shell command that I executed in a variable, but I couldn’t get it working. I tried like:

import os    

call = os.system("cat syscall_list.txt | grep f89e7000 | awk '{print $2}'")
print call

But it prints the result in terminal and prints the value of call as zero, possibly indicating as success. How to get the result stored in a variable?

  • 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-05-27T21:49:40+00:00Added an answer on May 27, 2026 at 9:49 pm

    Use the subprocess module instead:

    import subprocess
    output = subprocess.check_output("cat syscall_list.txt | grep f89e7000 | awk '{print $2}'", shell=True)
    

    Edit: this is new in Python 2.7. In earlier versions this should work (with the command rewritten as shown below):

    import subprocess
    output = subprocess.Popen(['awk', '/f89e7000/ {print $2}', 'syscall_list.txt'], stdout=subprocess.PIPE).communicate()[0]
    

    As a side note, you can rewrite

    cat syscall_list.txt | grep f89e7000
    

    To

    grep f89e7000 syscall_list.txt
    

    And you can even replace the entire statement with a single awk script:

    awk '/f89e7000/ {print $2}' syscall_list.txt
    

    Leading to:

    import subprocess
    output = subprocess.check_output(['awk', '/f89e7000/ {print $2}', 'syscall_list.txt'])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Ruby on Rails and I need to store a search result
I have id values for products that I need store. Right now they are
I need to store app specific configuration in rails. But it has to be:
I need to store user entered changes to a particular table, but not show
I'm new to PHP and SQL, but I need a way to store the
I need to store the result set of a stored procedure in a temporary
i need to store a DatSet value into ArrayList while(result.next()) { String Adress= result.getString(1);
I need to store a large table (several millions or rows) that contains a
My requirement is to store the result of an sqlplus operation into a variable
I need to store numbers that represent currency amounts in 2dp to be output

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.