PASSWORD = '123' # replace this with something good EMAIL = 'aafshar@gmail.com' import pexpect # spawn the child process child = pexpect.spawn('python manage.py syncdb') # Wait for the application to give us this text (a regular expression) child.expect('Would you like to create one now.*') # Send this line in response child.sendline('yes') # Again wait for this, and send what is needed child.expect('Username.*') # A blank string for the default username child.sendline('') # And so it goes on child.expect('E-mail.*') child.sendline(EMAIL) child.expect('Password.*') child.sendline(PASSWORD) child.expect('Password.*') child.sendline(PASSWORD) # This means wait for the end of the child's output child.expect(pexpect.EOF, timeout=None)