Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/324.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# 从process.StandardOutput.ReadToEnd()读取时,进程启动时返回null_C#_Excel_Process_Vsto - Fatal编程技术网

C# 从process.StandardOutput.ReadToEnd()读取时,进程启动时返回null

C# 从process.StandardOutput.ReadToEnd()读取时,进程启动时返回null,c#,excel,process,vsto,C#,Excel,Process,Vsto,目标:从VSTOExcel加载项项目启动一个新流程,该项目使用putty(plink)运行一些脚本,并阅读StandardOutput以获得结果 问题:process.StandardOutput.ReadToEnd()每次都返回空字符串。但是,当从控制台应用程序调用相同的函数时,它可以完美地工作。我认为可能存在一些身份验证问题,因为在前一种情况下Excel正在启动该过程,而在后一种情况下用户启动 我的代码: public partial class ThisAddIn {

目标:从
VSTO
Excel加载项项目启动一个新流程,该项目使用
putty(plink)
运行一些脚本,并阅读
StandardOutput
以获得结果


问题:
process.StandardOutput.ReadToEnd()每次都返回空字符串。但是,当从控制台应用程序调用相同的函数时,它可以完美地工作。我认为可能存在一些身份验证问题,因为在前一种情况下Excel正在启动该过程,而在后一种情况下用户启动


我的代码:

 public partial class ThisAddIn
    {
      const String DOMAINS_COMMAND ="some_command";  
      string HOST = "some_host";
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            execute();

        }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
        }
        public void execute()
        {
            try
            {                            
                Process p = new Process();
                ProcessStartInfo ps = new ProcessStartInfo();               
                ps.FileName = "plink"; 
                ps.Arguments = "-ssh " + HOST + " " + DOMAINS_COMMAND;
                ps.RedirectStandardOutput = true;
                ps.RedirectStandardError = true;
                ps.UseShellExecute = false;
                ps.CreateNoWindow = true;                
                p.StartInfo = ps;   
                p.Start();
                p.WaitForExit();
                string rs = p.StandardOutput.ReadToEnd();
                MessageBox.Show("value of result:"+rs);
            }

            catch
            { }


        }
        #region VSTO generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }

        #endregion
    }
public分部类ThisAddIn
{
const String DOMAINS\u COMMAND=“some\u COMMAND”;
string HOST=“some_HOST”;
私有void ThisAddIn_启动(对象发送方,System.EventArgs e)
{
执行();
}
私有void ThisAddIn_关闭(对象发送方,System.EventArgs e)
{
}
public void execute()
{
尝试
{                            
过程p=新过程();
ProcessStartInfo ps=新的ProcessStartInfo();
ps.FileName=“plink”;
ps.Arguments=“-ssh”+主机+”“+域\u命令;
ps.RedirectStandardOutput=true;
ps.error=true;
ps.UseShellExecute=false;
ps.CreateNoWindow=true;
p、 StartInfo=ps;
p、 Start();
p、 WaitForExit();
字符串rs=p.StandardOutput.ReadToEnd();
MessageBox.Show(“结果值:+rs”);
}
抓住
{ }
}
#区域VSTO生成的代码
/// 
///设计器支持所需的方法-不修改
///此方法的内容与代码编辑器一起使用。
/// 
私有void InternalStartup()
{
this.Startup+=new System.EventHandler(ThisAddIn\u启动);
this.Shutdown+=new System.EventHandler(ThisAddIn\u Shutdown);
}
#端区
}