Is there any way that I can create a program where it gives input to another file and and collects its output?

The best that google give me is this. And I tried to recreate (read: copying the code in some unknown manner (read: stabbing in the dark))

And I got this

```
import time
string="file.py"
process=subprocess.Popen(string,stdin=subprocess.PIPE,stdout=subprocess.PIPE);
process.stdin.write("3 5")
time.sleep(1)
print process.stdout.read()

```

And it gives me error 

```
  File "D:\Pekerjaan non website\IO\reader.py", line 3, in <module>
    process=subprocess.Popen(string,stdin=subprocess.PIPE,stdout=subprocess.PIPE);
NameError: name 'subprocess' is not defined

```

Can anybody tell me how to create that program. (

Note: I have no knowledge in this kind of program I/O or subprocess

Note: It's up to you. Where you will explain this from my code or throw my code away and explain this from zero.

Thank you beforehand.

(PS: If my previous statement is confusing. My point is simple: Can you teach me? :))
['https://Stackoverflow.com/questions/23051085', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2872852/']
[subprocess](https://docs.python.org/2/library/subprocess.html) is a stdlib module that you need to import (the same way `time` is) - so you just need to:

```
import subprocess

```

some time before you try to use the functions in it (usually, you want to do this near the top of your code, right underneath your current `import time`).
In addition to lvc's answer you should consider using [Popen.communicate()](https://docs.python.org/library/subprocess.html#subprocess.Popen.communicate). something like,

```
import subprocess
string="file.py"
process=subprocess.Popen(string,stdin=subprocess.PIPE,stdout=subprocess.PIPE)
res=process.communicate("3 5")
print res[0]

```

In this way you don't have to use that sleep command.it'll Wait for process to terminate and return a tuple as (stdoutdata, stderrdata).