最近研究VIP音乐解密,发现作者提供了一个CLI,于是准备写个监听小程序,监听下载音乐文件夹,自动通过CLI解密然后上传到我的NAS,这个CLI比较特殊,输出信息是通过Error获取到的,拿Output反而会卡住,比较不寻常,记录一下执行方法。


    /// <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 日
如果觉得我的文章对你有用,请随意赞赏