gpt4 book ai didi

c# - 将信息传回控制台应用程序窗口的批处理

转载 作者:可可西里 更新时间:2023-11-01 11:06:54 26 4
gpt4 key购买 nike

我有一个运行 .bat.vbs 文件的控制台应用程序。

启动这些进程的方法如下:

public void runProcess(string aPath,string aName,string aFiletype)
{
string stInfoFileName;
string stInfoArgs;

if(aFiletype == "bat")
{
stInfoFileName = (@aPath + @aName);
stInfoArgs = string.Empty;
}
else
{ //vbs
stInfoFileName = @"cscript";
stInfoArgs = "//B //Nologo " + aName;
}

this.aProcess.StartInfo.FileName = stInfoFileName;
this.aProcess.StartInfo.Arguments = stInfoArgs;
this.aProcess.StartInfo.WorkingDirectory = @aPath;

this.aProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
this.aProcess.Start();

Console.WriteLine("information passed from batch: ???");

this.aProcess.WaitForExit(); //<-- Optional if you want program running until your script exit
this.aProcess.Close();
}

它正在启动的当前 .bat 文件用于通过 ftp 发送数据(ftpftpssftp )。

当进程运行时,所有信息都显示在进程窗口中,例如可能会发生错误,文件不会传输,并且会在该“子”进程窗口中显示详细信息。该过程完成后,“子”窗口将随消息一起消失。

我能否以某种方式将这些有用信息返回到我的主控制台应用程序窗口?

最佳答案

检查进程退出代码 ( Process.ExitCode ) 和/或捕获控制台输出。

参见 Capturing console output from a .NET application (C#)


尽管您最好使用一些 native .NET SFTP/FTP 库。

对于 SFTP,请参阅 SFTP Libraries for .NET

对于 FTP 和 FTPS,可以使用 FtpWebRequest来自 .NET 框架。


如果您想要一体化解决方案,我可以谦虚地向您推荐我的 WinSCP .NET assembly .使用程序集,您可以为 SFTP、FTP 和 FTPS 使用相同的代码。在内部,程序集实际运行 WinSCP 控制台应用程序。所以它做的事情与您尝试自己编写代码的事情相同。

关于c# - 将信息传回控制台应用程序窗口的批处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30889247/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com