0

我的问题是当命令行运行时它不会在我的解密文本文件中添加任何内容。我在decrypt.txt 文件中添加了文本,以查看它是否写入了它,因为文本被删除了。

        System.Diagnostics.ProcessStartInfo psi =
        new System.Diagnostics.ProcessStartInfo("cmd.exe");
        psi.CreateNoWindow = true;
        psi.UseShellExecute = false;
        psi.RedirectStandardInput = true;
        psi.RedirectStandardOutput = true;
        psi.RedirectStandardError = true;
        psi.WorkingDirectory = "c:\\";

        System.Diagnostics.Process process = System.Diagnostics.Process.Start(psi);
        string sCommandLine = "echo femme toxin sorghum| gpg.exe --batch --passphrase-fd 0 --decrypt E:\\entemp.txt > E:\\detemp.txt";
        process.StandardInput.WriteLine(sCommandLine);
        process.StandardInput.Flush();
        process.StandardInput.Close();
        process.WaitForExit();
        process.Close();
4

1 回答 1

2

我最近一直在做很多 gpg.exe 的东西......

我认为您正在将您的 gpg 命令标准重定向到您的文件...

你可能想要更多这样的东西

echo password123|gpg.exe --yes --batch --passphrase-fd 0 --decrypt --output c:\file.txt c:\file.gpg

你也可以直接在你的进程中调用 gpg.exe,而不是调用 cmd 然后传递一个命令......如果你这样做,你将取消“echo”的东西并将--yes ... c:\file.gpg等等添加到参数属性中。那么......你的第一个输入就像gpgProc.standardinput.writeline(password123);

此方法还使您能够直接获取 gpg.exe 的标准错误输出和处理退出代码,而不是 cmd.exe 退出代码等。

也许这会有所帮助...

于 2011-08-06T02:34:26.010 回答