Responding to cmd prompt programmatically in C#
I'm stuck trying to send commands to a cmd prompt that is waiting for my input.
The command in question is JavaLoader, which if I try to use on a BlackBerry device with a password it prompts me for a password. I would like to enter a password but using C# code.
Assuming that I've successfully created the cmd.exe using a Process like so:
process = new Process();
// Invokes the cmd process specifying the command to be executed.
string cmdProcess = string.Format(System.Globalization.CultureInfo.InvariantCulture, @"{0}\cmd.exe", new object[] { Environment.SystemDirectory });
// Pass executing file to cmd (Windows command interpreter) as a arguments
//Removed /C tells cmd that we want it to execute the command that follows, and then exit.
string cmdArguments = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}", new object[] { command });
// Pass any command line parameters for execution
if (arguments != null && arguments.Length > 0)
{
cmdArguments += string.Format(System.Globalization.CultureInfo.InvariantCulture, " {0}", new object[] { arguments, System.Globalization.CultureInfo.InvariantCulture });
}
process.StartInfo.FileName = cmdProcess;
process.StartInfo.Arguments = cmdArguments;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.UseShellExecute = false; // Must be false for redirection
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardInput = true;
bool s = process.Start();
How do I go about responding the cmd's prompt for a passwords?
I've tried getting the Input stream and using .WriteLine("randompassword") like so:
while (process.Responding)
{
sw.WriteLine(response);
}
Another thing I've noticed is the prompt for a password is not being picked up as Output or Error and the application will开发者_运维技巧 in fact hang here because it's waiting for my input.
精彩评论