r/pythonhelp • • Jan 14 '22

Script that Automatically provides input() in terminal.

File A is designed to automate a process and has a for loop that calls file B.

File B has an input() function, and when it it called it halts the for loop until a user input is provided.

Is there a way where I can automatically fill the input within the terminal?

(Note: I am unable to alter file B)

3 Upvotes

10 comments sorted by

View all comments

Show parent comments

1

u/Muskratbest2 Jan 14 '22

My apologies, did this fix the formatting?

1

u/Goobyalus Jan 14 '22

Not really, but I see now that the os.system changed from A to B.

Do you need to run B with os.system, or can you import B?

1

u/Muskratbest2 Jan 14 '22

I believe that I do need to run with os.system, yes

Also yes my apologies that was a typo

1

u/Goobyalus Jan 14 '22

os.system doesn't give you control over the environment of the subprocess.


With the subprocess module, you could take control over stdin, stdout, and stderr and communicate with the subprocess that way, writing into stdin from A's process to B's process as though A were a user in the terminal.


Using os.system or subprocess to run one python script from another is probably a mistake.

1

u/Muskratbest2 Jan 14 '22

Okay thank you for your help!