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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:41:44+00:00 2026-06-10T18:41:44+00:00

I think that’s should work. I want to get output of this command grep

  • 0

I think that’s should work. I want to get output of this command
“grep -l %s *.py” % tag for each tag,
on created file with tag name.

import os
import sys

results_dir = '/home/ks/one/work/tn/format-description 15852/results'
converters_dir = '/home/ks/one/work/cvr'
export_dir = '/home/ks/one/work/epr'
all_dirs = {'cvr':cvrs_dir, 
            'epr':eprs_dir}

tags = [tag.strip() for tag in open('new file').readlines()]
for coe, directory in all_dirs.items(): # coe - type of our file
    os.chdir(results_dir)
    for tag in tags:
        tag_file = open(coe + ' ' + tag, 'w')
        sys.stdout = tag_file
        os.chdir(directory)
        os.system("grep -l %s *.py" % tag)
        tag_file.close()

But all what I see when script is runned – it’s output in my console.

  • 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-10T18:41:45+00:00Added an answer on June 10, 2026 at 6:41 pm

    Use the subprocess module of Python

    http://docs.python.org/library/subprocess.html

    The documentation contains extensive documentation and examples.

    The other (poor) option with os.system() is redirecting the output to a file

    os.system('do_something >/tmp/myoutput')
    

    and then later reading the output file from within Python. However this is ugly
    and likely not very portable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think that this should be easy, but I'm not able to get it
just think that when I opened my file then when I want to write
I think that this is a relatively simple question. I just want to know
Think that I have many activities,and all I want is this: I have a
I think that it should be possible to get all the activities from 'third-party'
I think that it should exist a better way of doing this... I'm using
I think that handlers in android are tools to get different objects that are
I think that this problem can be sorted using reflection (a technology which I'm
I think that some newer languages like JS can do this natively, but I
I think that this is not possible because Int32 has 1 bit sign and

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.