I have been trying to make an .exe file that I have become more automated by using Mathematica, but I am having trouble getting it to work. The file is based in command prompt and I basically need to do:

  1. Open program
  2. enter string
  3. press enter key
  4. enter string
  5. press enter key
  6. enter string
  7. press enter key
  8. press enter key

I do not need any of the output from the program since it is making a new txt file for me which I will read separately. I do not know how to go about "pressing the enter key" or even inputting the string I need to. I can get Mathematica to open the file with SystemOpen[], but I can not get it to enter anything through Mathematica itself. Let me know if you need anymore clarification!

  • $\begingroup$ Please check if the you are happy with the new title. I changed it in hope that then more people with a similar question will find this question. $\endgroup$
    – Johu
    Sep 4, 2018 at 23:09

1 Answer 1


See the manual for StartProcess. With a small adaptation to the example given there you should be able to achieve the goal.

Just an example application

pathtoexe = "echo";

Opens a stream, which in Mathematica is called ProcessObject

process = StartProcess[pathtoexe]

Writes three lines to a standard input:

WriteLine[process, "write string one"];
WriteLine[process, "write string two"];
WriteLine[process, "write string three"];

Note, that each time WriteLine by default already adds the "enter" as a hidden linefeed character \n. Thus, if you just need an extra "enter" in the end, just send a empty string once more:

WriteLine[process, ""];

Close the process, if it already has not stopped:


If this does not solve your problem, then please extend your question with a more specific example, such that we could run the same code as you and help you more efficiently.

  • $\begingroup$ This ended up working! Thank you very much for the fast help!!! $\endgroup$
    – JStefanik
    Sep 4, 2018 at 23:06
  • $\begingroup$ You are welcome! Do not forget to accept and upvote the solution, which you find helpful! $\endgroup$
    – Johu
    Sep 4, 2018 at 23:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.