从KPScript.exe控制台输出读取值

时间:2019-06-19 14:29:28

标签: c# stdout keepass

我想在C#应用程序中利用单命令操作(https://keepass.info/help/v2_dev/scr_sc_index.html)从KeePass数据库读取值。当我在cmd窗口中的KPScript.exe上执行命令时,控制台输出

pass
OK: Operation completed successfully.

pass是从数据库中读取的条目的密码。

我想获得这个pass以便在应用程序中使用它。我使用以下代码来完成此操作,但是消息框显示了字符串OK: Operation completed successfully.

var proc = new Process
{
    StartInfo = new ProcessStartInfo
    {
        FileName = KPScript.exe,
        Arguments = "-c:GetEntryString -Field:Password " + <database_path> + " -pw:password -ref-Title:'Entry1'",
        UseShellExecute = false,
        RedirectStandardOutput = true
    }
};

proc.Start();

MessageBox.Show(proc.StandardOutput.ReadLine());

我也尝试了以下操作,但是它不显示pass

proc.OutputDataReceived += (sender, arguments) => MessageBox.Show("received output: " + arguments.Data);
proc.Start();
proc.BeginOutputReadLine();

如何获取pass

0 个答案:

没有答案