How to pass string input to console from C#?
I follow the below steps to pass a string input to a console from C#:
I allocate a console to Visual Studio Process using AllocConsole() method,
by pInvoking Kernel32.dll.
I call a Perl process from Visual Studio (C#). The Perl process attaches
to this console automatically. (which is OK for me).
I kill 'only' Perl Process by passing Ctrl C signal to it.( I suppress
Ctrl C signal for Visual Studio)
Now I want to send a command (a simple string basically) to this console.
What is the method to pass input string to the console?
I am trying to use writeConsoleInput(), by pInvoking Kernel32.dll, but I
am stuck on the arguments of this function. The function signature is:
[DllImport("kernel32", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool WriteConsoleInput(IntPtr hConsoleInput,
[Out] INPUT_RECORD[] lpBuffer,
int nLength,
out int lpNumberOfEventsWritten);
Can somebody help me to successfully call WriteConsoleInput() or by giving
an alternative option.
Many Thanks!
No comments:
Post a Comment