Running a program from another program.

Discussion in 'Python' started by Laurent Verweijen, Jun 17, 2010.

  1. I have a program called increment.py as follows:

    #!/usr/bin/python
    n = 0
    while True:
    n = int(raw_input(n)) + 1

    This is probably very easy to understand, but I want to run this program
    from another python program.
    Below is an attempt

    >>> from subprocess import *
    >>> p = Popen(["python", "increment.py"], stdin=PIPE,

    stdout=PIPE)
    >>> p.communicate("5")

    Traceback (most recent call last):
    File "increment.py", line 4, in <module>
    n = int(raw_input(n)) + 1
    EOFError: EOF when reading a line
    ('06', None)
    >>> p.communicate("7")

    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "/usr/lib/python2.6/subprocess.py", line 701, in
    communicate
    return self._communicate(input)
    File "/usr/lib/python2.6/subprocess.py", line 1184, in
    _communicate
    self.stdin.flush()
    ValueError: I/O operation on closed file

    How do I make sure the inputstream stays open after the first call to
    communicate?
     
    Laurent Verweijen, Jun 17, 2010
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Pierre-Yves
    Replies:
    6
    Views:
    7,277
    Jim Gibson
    Mar 5, 2004
  2. Mandhare Prashant
    Replies:
    1
    Views:
    798
    Jack Klein
    Mar 14, 2005
  3. Replies:
    1
    Views:
    485
    Walter Roberson
    Aug 12, 2005
  4. Lorenzo Bettini
    Replies:
    3
    Views:
    632
    Lorenzo Bettini
    Sep 24, 2005
  5. Alexander Mahone

    Running a program (gperf) inside another C program

    Alexander Mahone, May 26, 2008, in forum: C Programming
    Replies:
    4
    Views:
    419
    Flash Gordon
    May 26, 2008
Loading...

Share This Page