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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:12:56+00:00 2026-06-05T08:12:56+00:00

I am trying to wrap gnugo in a python script. I’ve gone over the

  • 0

I am trying to wrap gnugo in a python script.

I’ve gone over the other questions in SO about wrapping CLI applications here and here and though they’ve helped somewhat, I haven’t been able to get my script to work completely. It appears the process is killed after the first input from stdin.

The script looks like this:

import subprocess 

proc = subprocess.Popen(['gnugo', '--mode', 'gtp'], stdout=subprocess.PIPE, stdin=subprocess.PIPE)

c = raw_input('first command: ')

while True:
    r = proc.communicate(c)
    print 'gnugo says: ' + str(r)
    c = raw_input('next command: ')

The error I’m getting is this:

$ python testgnu.py
first command: play b c4
gnugo says: ('= \n\n', None)
next command: genmove w
Traceback (most recent call last):
  File "testgnu.py", line 8, in <module>
    r = proc.communicate(c)
  File "/usr/local/Cellar/python/2.7.3/lib/python2.7/subprocess.py", line 754, in communicate
    return self._communicate(input)
  File "/usr/local/Cellar/python/2.7.3/lib/python2.7/subprocess.py", line 1307, in _communicate
    self.stdin.flush()
ValueError: I/O operation on closed file

I am running python 2.7.3 (and it probably doesn’t matter but the gnugo version is 3.8).

Some answers in the other questions suggested pexpect but I’d like to use as few external libraries as possible.

  • 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-05T08:12:57+00:00Added an answer on June 5, 2026 at 8:12 am

    Your issue is that Popen.communicate closes the file after performing its reads and writes.

    You will have to manually call proc.stdin.write(...) to send the process text and proc.stdout.read*() to read text:

    while True:
        proc.stdin.write(c)
        r = proc.stdout.readline()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to wrap my head around a particular subtlety of using asynchronous script
Trying to wrap my brain around animations here. Here is my basic situation: _________
I've been trying to wrap my head around how threads work in Python, and
I'm trying to wrap my head about how to properly implement an OOP design
Trying to wrap my head around updating UI controls from other threads. Currently using
Trying to wrap my head around the jQuery .not() function, and running into a
Im trying to wrap my head around MVVM. I understand a lot of it,
Just trying to wrap my brain around open source cloud. 1) Is OpenStack running
I'm trying to wrap printf in a C program (well, actually _snprintf but this
I'm trying to wrap a C++ library (libclang) into a C# wrapper, using PInvoke.

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.