Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在C中以编程方式响应cmd提示符#_C#_Blackberry_Process_Cmd_Command Prompt - Fatal编程技术网

C# 在C中以编程方式响应cmd提示符#

C# 在C中以编程方式响应cmd提示符#,c#,blackberry,process,cmd,command-prompt,C#,Blackberry,Process,Cmd,Command Prompt,我一直在尝试向等待输入的cmd提示符发送命令 有问题的命令是JavaLoader,如果我试图在黑莓设备上使用密码,它会提示我输入密码。我想输入密码,但使用C#代码 假设我已使用如下过程成功创建cmd.exe: process = new Process(); // Invokes the cmd process specifying the command to be executed. string cmdProcess = string.Format(System.Globalizatio

我一直在尝试向等待输入的cmd提示符发送命令

有问题的命令是JavaLoader,如果我试图在黑莓设备上使用密码,它会提示我输入密码。我想输入密码,但使用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();
如何响应cmd提示输入密码

我尝试获取输入流并使用.WriteLine(“随机密码”),如下所示:


我注意到的另一件事是,输入密码的提示没有作为输出或错误被拾取,应用程序实际上会挂在这里,因为它正在等待我的输入。

也许这会有所帮助:您也可以在使用-wYes执行“javaloader.exe”时传递密码,但在最后一次尝试时,它会提示我输入,即使我传递密码。所以我仍然需要一些方法来回应这个提示。
while (process.Responding)
{
   sw.WriteLine(response);
}