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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:57:21+00:00 2026-06-14T16:57:21+00:00

We’re using a bit of compiled python code that we don’t have the source

  • 0

We’re using a bit of compiled python code that we don’t have the source to. The code prompts for user input and we’re trying to automate that portion.

Basically asks for username, password, then some various questions depending on certain circumstances. I don’t know whether the compiled function is using raw_input, input or something else.

I’ve been able to use StringIO to replace stdin w/ the username and password and I can replace stdout with my own class and figure out which prompt is coming up, but I’m stumped when it comes to selectively placing data into stdin based on what I read from stdout.

import sys
import re
from StringIO import StringIO

def test():
    overwrite = raw_input("The file exists, overwrite? ")
    notify = raw_input("This file is marked for notifies.  Notify?")
    sys.stdout.write("Overwrite: %s, Notify: %s" % (overwrite,notify))

class Catcher(object):
    def __init__(self):
        pass

    def write(self, msg):
        if re.search("The file exists, overwrite", msg):
            # put data into stdin 
        if re.search("The file is marked for notification", msg):
            # put data into stdin

sys.stdout = Catcher()
test()

I can’t just preload a StringIO object, because the questions may vary depending on the circumstances, but I need to automate feeding into stdin because they’re trying to put this into an automated build system, so they’ll be providing the defaults via the command line to answer any questions that occur.

If I set stdin to an empty StringIO object before calling the compiled function, then it just errors out with EOF – not sure how to make it wait for input.

Something like this:

import sys
import re
from StringIO import StringIO

def test():
    overwrite = raw_input("The file exists, overwrite? ")
    notify = raw_input("This file is marked for notifies.  Notify?")
    sys.__stdout__.write("Overwrite: %s, Notify: %s" % (overwrite,notify))

class Catcher(object):
    def __init__(self, stdin):
        self.stdin = stdin

    def write(self, msg):
        if re.search("The file exists, overwrite", msg):
            self.stdin.write('yes\n')
        if re.search("The file is marked for notification", msg):
            self.stdin.write('no\n')

sys.stdin = StringIO()
sys.stdout = Catcher(sys.stdin)
test()

Produces:

Traceback (most recent call last):
  File "./teststdin.py", line 25, in <module>
    test()
  File "./teststdin.py", line 8, in test
    overwrite = raw_input("The file exists, overwrite? ")
EOFError: EOF when reading a line

Any ideas?

  • 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-14T16:57:23+00:00Added an answer on June 14, 2026 at 4:57 pm

    If you want to read from a StringIO you’ve just written to, you have to rewind it first to the position you’ve started writing.
    Also, your second search tests for the wrong string.

    This should work:

    import sys
    import re
    from StringIO import StringIO
    
    def test():
        overwrite = raw_input("The file exists, overwrite? ")
        notify = raw_input("This file is marked for notifies.  Notify?")
        sys.__stdout__.write("Overwrite: %s, Notify: %s" % (overwrite,notify))
    
    class Catcher(object):
        def __init__(self, stdin):
            self.stdin = stdin
    
        def write(self, msg):
            if re.search("The file exists, overwrite?", msg):
                self.stdin.truncate(0)
                self.stdin.write('yes\n')
                self.stdin.seek(0)
            if re.search("This file is marked for notifies.  Notify?", msg):
                self.stdin.truncate(0)
                self.stdin.write('no\n')
                self.stdin.seek(0)
    
    sys.stdin = StringIO()
    sys.stdout = Catcher(sys.stdin)
    test()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a small JavaScript validation script that validates inputs based on Regex. I
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have thousands of HTML files to process using Groovy/Java and I need to

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.