Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There's a fundamental difference between the <em>standard input</em> of the child process, and the console that it is attached to. A command interpreter in interactive mode is expecting to be talking <em>either</em> to a console <em>or</em> to a pipe/file as its standard input, and it changes its behaviour to match which one it finds. For a pipe/file, it just makes a simple call the <a href="http://msdn.microsoft.com/en-gb/library/aa365467%28VS.85%29.aspx" rel="nofollow" title="ReadFile Function"><code>ReadFile()</code></a> function. For a console, however, it receives input through <a href="http://msdn.microsoft.com/en-gb/library/ms684961%28VS.85%29.aspx" rel="nofollow" title="ReadConsoleInput Function"><code>ReadConsoleInput()</code></a>, where non-alphanumeric keys are recognizable by their virtual key codes. </p> <p>See the <a href="http://doxygen.reactos.org./da/d2c/base_2shell_2cmd_2cmd_8h_ab56d2b86e2487d35eab0eae73ba5afcb.html#ab56d2b86e2487d35eab0eae73ba5afcb" rel="nofollow" title="ReadCommand()"><code>ReadCommand()</code></a> function in the ReactOS <code>CMD</code> for an example.</p> <p>If you write a byte with the value 9 down a pipe to the standard input of a process, that's what it will see from its call to <code>ReadFile()</code>. But it won't treat it as a <kbd>Tab</kbd> keypress, because (for starters) it isn't one; it's just byte value 9 coming down a pipe. Moreover, the command-line editing that a command interpreter does in interactive mode only occurs when the standard input is detected to be a console, not when it is a pipe or a file. The command interpreter uses <code>ReadConsoleInput()</code>, which doesn't read buffers of bytes but reads sequences of <a href="http://msdn.microsoft.com/en-gb/library/ms683499%28VS.85%29.aspx" rel="nofollow" title="INPUT_RECORD Structure"><code>INPUT_RECORDs</code></a>; and thus you have to <a href="http://msdn.microsoft.com/en-gb/library/ms687403%28VS.85%29.aspx" rel="nofollow" title="WriteConsoleInput Function"><code>WriteConsoleInput()</code></a> to that console handle an appropriate <code>INPUT_RECORD</code> simulating the <kbd>Tab</kbd> key if you want the command interpreter to see a <kbd>Tab</kbd> keypress in its input stream.</p> <p>Of course, since you've set <code>StartInfo.RedirectStandardInput</code> to <code>true</code>, under the covers .NET has connected the standard input of the command interpreter process to a pipe; and so the command interpreter is just calling <code>ReadFile()</code>, without doing any interactive command-line editing, as it would if its standard input had been a console. Even if you could find and open a handle to the command interpreter process' console, and write a <code>INPUT_RECORD</code> for a <kbd>Tab</kbd> key to it, the command interpreter is reading a pipe for its standard input, and ignoring its console.</p> <p>If you want a command interpreter to act just as it would if it were talking to a console, command line editing and all, you have to spawn the process <em>with its standard input as a console</em>, whose handle you have to (then) obtain so that you can simulate keypresses with <code>WriteConsoleInput()</code>. That's fairly difficult within .NET.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload