Winforms 从winform运行cmd

Winforms 从winform运行cmd,winforms,cmd,Winforms,Cmd,我有一个关于从winform运行cmd的问题 我已成功连接到远程计算机(infotrend磁盘服务器)并从中获取信息 但是,我无法在远程计算机上执行“创建磁盘部件”这样的操作 下面我已经写了这些代码 InfotrendProcess.StartInfo.UseShellExecute = false; InfotrendProcess.StartInfo.RedirectStandardInput = true; InfotrendProcess.StartInfo.RedirectStanda

我有一个关于从winform运行cmd的问题

我已成功连接到远程计算机(infotrend磁盘服务器)并从中获取信息

但是,我无法在远程计算机上执行“创建磁盘部件”这样的操作

下面我已经写了这些代码

InfotrendProcess.StartInfo.UseShellExecute = false;
InfotrendProcess.StartInfo.RedirectStandardInput = true;
InfotrendProcess.StartInfo.RedirectStandardOutput = true;
InfotrendProcess.StartInfo.RedirectStandardError = true;
InfotrendProcess.StartInfo.WorkingDirectory = workingPath;

InfotrendProcess.StartInfo.FileName = "C:\\Windows\\System32\\cmd.exe";
InfotrendProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
InfotrendProcess.StartInfo.CreateNoWindow = true; 

const string  quote = "\""; 

cmd_message = "java -jar " + quote +  "runCLI" + quote; (MANAGED TO START CLI RUN COMMAND STEP 1) 
InfotrendProcess.StartInfo.Arguments = "/K " + cmd_message;
            
InfotrendProcess.OutputDataReceived += InfotrendProcess_OutputDataReceived1;
InfotrendProcess.ErrorDataReceived += InfotrendProcess_ErrorDataReceived;
InfotrendProcess.Start();

       using (StreamWriter sw = InfotrendProcess.StandardInput) (MANAGED TO CONNECT AND SEND DELETE 
                                                                      PART COMMAND STEP 2)
            {
              sw.WriteLine("connect " + IPNumber);
              Thread.Sleep(1000);
              sw.WriteLine("del part 01D9F2C6614DF837"); (COULD NOT SEND RESPOND y/s, MAKES NEW LINE)
              sw.WriteLine("y")
            }

我无法发送“y/n”响应,因为我必须在一段时间后将其发送到同一行。相反,它会生成一个新行。我应该使用其他方式吗?有人可以帮助我,如何运行最终命令。

写:输出后不要换行,写:输出后换行。请更清楚地告诉我“不要换行”的内容,一些代码行可能会有用谢谢你的帮助我不明白你的意思是在时间段后发送“y”。当“del”操作完成时,我是否应该发送“y”操作?因为这正是他所做的,它在一段时间后要求确认“您将要删除分区。是否要删除y/n”,所以我必须发送“y”表示是,或“n”表示否。。。。我必须在同一行中发送此命令。。但是上面的代码在新行中发送确认。由于我已通过空的确认,它写入“失败”,并在新行sw.Write(“del part 01D9F2C6614DF837”)中将“y”命令独立识别为nothing;sw.WriteLine(“y”)这将使两条语句保持在一行上。