views:

87

answers:

1

I create a child console application with

_process = new Process();
_process.StartInfo.FileName = @"cmd.exe";
_process.StartInfo.UseShellExecute = false;
_process.StartInfo.RedirectStandardInput = true;
_process.StartInfo.RedirectStandardOutput = true;
_process.StartInfo.CreateNoWindow = true;

_proccess.Start();

Now I can go to c:\aaa

_process.StandardInput.Write("cd c:\\aaa\xD\xA");

But normally user can type c:\ + TAB + ENTER. How can I do the same? This does not work:

_process.StandardInput.Write("cd c:\\\0x9\xD\xA");
A: 

What about dipping into the Windows API?

using System.Runtime.InteropServices;
//...
[DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
private const int WM_CHAR = 0x0102;
private const int VK_TAB = 0x9;
private const int VK_RETURN = 0xD;
//...
SendMessage(_process.Handle, WM_CHAR, new IntPtr(VK_TAB), new IntPtr(0));
SendMessage(_process.Handle, WM_CHAR, new IntPtr(VK_RETURN), new IntPtr(0));

However that doesn't allways work according to Kevin Montrose's answer here.

Matt Blaine