以示例为例,我打开CMD并导航到要从中获取数据的文件夹,然后用它来打开到目前为止具有标准输入(全部同步)代码的arugents应用程序
public static Process Start(bool DoNotShowWindow = false)
{
ProcessStartInfo cmdStartInfo = new ProcessStartInfo
{
FileName = "cmd.exe",
RedirectStandardOutput = true,
RedirectStandardError = true,
RedirectStandardInput = true,
UseShellExecute = false,
CreateNoWindow = DoNotShowWindow
};
Process cmdProcess = new Process
{
StartInfo = cmdStartInfo,
EnableRaisingEvents = true
};
return cmdProcess;
}
//in other method
Process cli = InteractWithConsoleApp.Start();
cli.Start();
cli.StandardInput.WriteLine("cd /");
cli.StandardInput.WriteLine("cd " + path);
cli.StandardInput.WriteLine("fantasygold-cli getbalance abc");
Thread.Sleep(5000);
现在,当我使用StandardOutput.Readline时,它从头开始,并向我返回所有内容,例如版权的前两行,空行,甚至是输入(对于我而言),在等待5秒钟后我想读取行的结果或最后取决于我输入的位置。
我发现的一个解决方案是更改位置,但事实证明它不支持该位置,甚至无法复制到另一个流阅读器(该位置不是逐行显示的)。
好吧,我可以使用过滤器,例如检查双精度数或以F开头且长度为36的地址。问题是当我想像过去的事务一样获得整个JSON的语句时,我认为使用过滤器例如“ {”,然后检查“}”。此提示是错误的代码,我不希望这样做。
TLDR所以,这里解决我的问题的方法是什么:)
答案 0 :(得分:0)
我找到了答案,只需使用此cli.StartInfo.FileName = Directory.GetCurrentDirectory() + @"\SubfolderName\fantasygold-cli";
和诸如get cli.StartInfo.Arguments = "getbalance amunim"