Loading... 最近研究`VIP音乐解密`,发现作者提供了一个`CLI`,于是准备写个监听小程序,监听下载音乐文件夹,自动通过`CLI`解密然后上传到我的`NAS`,这个`CLI`比较特殊,输出信息是通过`Error`获取到的,拿`Output`反而会卡住,比较不寻常,记录一下执行方法。 ```csharp /// <summary> /// 执行命令行 /// </summary> public static async Task<string> ExecuteCommandLine(this string shell, bool isAppendExit = true) { var process = new Process { StartInfo = { FileName = "cmd.exe", UseShellExecute = false, RedirectStandardInput = true, RedirectStandardOutput = true, RedirectStandardError = true, CreateNoWindow = true, StandardErrorEncoding = Encoding.Default } }; if (isAppendExit) { shell += "&exit"; } process.Start(); await process.StandardInput.WriteLineAsync(shell); var output = await process.StandardOutput.ReadToEndAsync();//输出信息 var error = await process.StandardError.ReadToEndAsync();//错误信息 await process.WaitForExitAsync(); process.Close(); return error; } ``` 最后修改:2023 年 01 月 12 日 © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 0 如果觉得我的文章对你有用,请随意赞赏