I have the code below, where this encryption code works fine (creating an encrypted file) when it is called through Command Prompt, and the same one does not work when it is in Console Application.
var destFilePath = @"D:\test.gpg";
var recipient = "test@test.com";
var sourceFilePath = @"D:\test.txt";
var proc = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = string.Format("gpg2 --output {0} --encrypt --recipient {1} {2}",
destFilePath, recipient, sourceFilePath),
UseShellExecute = false,
RedirectStandardError = true,
RedirectStandardInput = true,
RedirectStandardOutput = true,
CreateNoWindow = true,
WorkingDirectory = @"C:\Program Files (x86)\GNU\GnuPG"
}
};
proc.Start();
proc.WaitForExit();
int rc = proc.ExitCode;
proc.Close();
Console.WriteLine(rc.ToString());
Console.ReadKey();
which returns error code 2 in ExitCode
Any ideas will help!
user1618825
source
share