The reason why you're seeing the command you just ran coming back in the channel is because Windows'
cmd.exe will by default run with “echo” on, which means it will print back the command to be executed before executing it and sending back the output produced by it.
You can use
job_start("cmd /q") to have it disable “echo” at startup, which should solve the problem and have your read from the channel return the first line produced by the
dir command. See documentation for
cmd.exe at Microsoft's website.
Another alternative is using, for example,
bash.exe from a distribution such as Git Bash, which will not produce the “echo” you've seen with
Note that a read from the channel will only produce the first line of output from
dir and further channel reads don't seem to send the next lines of output from that command. I haven't really used Vim jobs and channels extensively, so I'm not really sure what the issue there is. You might want to ask a separate question about that if you'd like to explore that further...
If all you want is to capture the output of an external command, a much easier approach is to use the
systemlist() functions, which will take care of all the details for you and simply return a string or list. For example, to put the output of
dir under the cursor in the current buffer, all you need is: