0

I have a program that I am using which takes input in terminal after you start the program. It will not take the input by adding it after the process name. How can I pass it what I want? I know I could use virtual keypresses, but that seems inefficient and non-pythonic, so it will be my last resort.

Below is an example of what I type and get when using the terminal, because I feel that I did not explain as well as I would have liked.

user:~ $ program_name
Enter your input here:
Ian Baker
  • 33
  • 1
  • 4
  • @downshift No, he's assing how to pass data to the program's standard input. – Barmar May 24 '17 at 22:33
  • 2
    Use the `subprocess` module, with the `stdin=subprocess.PIPE` option. – Barmar May 24 '17 at 22:33
  • This has already been answered I think, try this link: https://stackoverflow.com/a/5405460/2241241 – fbence May 24 '17 at 22:34
  • So, what exactly is wrong with the example in your question? When the program says, "Enter your input here:", you would normally type the input. What do you want to do instead? – DYZ May 24 '17 at 22:54
  • @DYZ His question is clear (to me): "How can I pass it what I want?" – Barmar May 24 '17 at 22:58
  • @fbence He's not asking how to read input. He's asking how to provide input to a shell command that he executes from the script. – Barmar May 24 '17 at 22:59
  • oh, sure, yeah, in that case your subprocess solutions seems to be the way to go – fbence May 24 '17 at 23:02
  • @Barmar If that's what he asks, then he should use shell redirection from a file, as in `program_name < data`. – DYZ May 24 '17 at 23:02
  • @DYZ The question doesn't say anything about a file. He probably wants to provide the input from Python variables. – Barmar May 24 '17 at 23:06
  • @Barmar That's why I believe neither you nor I understand the question well enough to give a qualified answer. Perhaps you are right. – DYZ May 24 '17 at 23:07
  • 1
    @DYZ I don't think it's necessary to answer. There are other questions that explain how to give input to a program from Python, just vote to close it as a duplicate. – Barmar May 24 '17 at 23:15

0 Answers0