Search code examples
pythonpython-3.xdistributed-computing

Sending a string to a program


I am trying to send a string from a program 1 to another program program 2, both in python 3
e.g.

#_____________________________________1.py
a = input('Type in a string: ')
#                                     send somehow a string a from this program
#                                     to the second program

I want to somehow send a string a to my second program so it will print out a:

#_____________________________________2.py
#                                     receive somehow a string from the first
#                                     program and store it in a
print(a)

How do I do this?

I am still a beginner programmer and would love it if you could help me.

  1. I need to be able to enter the string in 1.py
  2. I need then be able to access the string that I entered from 2.py.
  3. I have to have them as two separate files.

ANSWER:

I found a way to solve this.

import subprocess
username = input()
subprocess.Popen(['python.exe', 'file.py', username])

Solution

  • I found the answer.

    import subprocess
    username = input()
    subprocess.Popen(['python.exe', 'file.py', username], subprocess.creationflags=CREATE_NEW_CONSOLE)