How do you enter something at a DOS prompt Programmatically?

后端 未结 3 1152
温柔的废话
温柔的废话 2020-12-14 09:37

I have program, that must interact with a DOS program before my program can continue what it is doing. I\'m trying to avoid my user from having to interact with this dos pro

相关标签:
3条回答
  • 2020-12-14 10:19

    You can pipe in a 'y' character into the program like so:

    echo y | executable.exe
    

    Multiple lines can be entered like so:

    (echo y
    echo n) | executable.exe
    

    ...which will pass first 'y' then 'n'.

    See tip from Microsoft here.

    0 讨论(0)
  • 2020-12-14 10:23

    The post from Microsoft also clearly says :

    Do not type a space between the "y" and the pipe symbol (|)

    and indeed, I noticed that in my case

    echo y | executable.exe

    doesn't work while

    echo y| executable.exe

    works fine

    0 讨论(0)
  • 2020-12-14 10:24

    I used the following, since "echo y | executable.exe" didn't worked for me

    // Write a "Y" to the process's input
    proc.StandardInput.WriteLine("Y");
    // Now that we've sent the confirmation "Y" wait for the process to exit
    proc.WaitForExit();
    

    as posted here: https://www.experts-exchange.com/questions/27024185/C-ProcessStart-How-to-automatically-press-the-Y-key.html

    0 讨论(0)
提交回复
热议问题