在 C# 中以编程方式响应 cmd 提示符
我试图将命令发送到正在等待我输入的命令提示符。
有问题的命令是 JavaLoader,如果我尝试在带有密码的 BlackBerry 设备上使用该命令,它会提示我输入密码。我想输入密码,但使用 C# 代码。
假设我已经使用如下所示的进程成功创建了 cmd.exe:
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 aboutResponse the cmd's提示输入密码?
我尝试获取输入流并使用 .WriteLine("randompassword") ,如下所示:
while (process.Responding)
{
sw.WriteLine(response);
}
我注意到的另一件事是密码提示没有被拾取为输出或错误,并且应用程序实际上会挂在这里,因为它正在等待我的输入。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论