I've encountered an unexpected problem with an .exe I use for my inter-process communication.
It seems to work in desktop directory but it fails and gives a weird unset in its code exitcode in my project directory.
I can't find the source of the problem. The exec is compiled to one file with all its libraries included and as you can see it works in the desktop directory but it stops in others. The same weird exitcode is given in the main program when it exits
var process = new Process
{
StartInfo = {
FileName = @"WF_Mag.exe",
Arguments =
$"\"{Account.Host}\" \"{Account.DbName}\" \"No\" \"{Account.Login}\" \"{Account.Password}\" \"{Account.DateFrom.ToString("yyyy-MM-dd")}\" \"{Account.DateTo.ToString("yyyy-MM-dd")}\" ",
CreateNoWindow = false,
UseShellExecute = false,
RedirectStandardError = true,
RedirectStandardOutput = true,
},
EnableRaisingEvents = true
};
process.OutputDataReceived += Process_OutputDataReceived;
process.Exited += (sender, args) =>
{
var proc = sender as Process;
if (proc != null)
{
var sb = new StringBuilder();
var exitCodeFlags = (ExitCodes)proc.ExitCode; // returns -532462766
if (exitCodeFlags.HasFlag(ExitCodes.ArgumentsError))
sb.Append("Błędna liczba argumentow \n");
if (exitCodeFlags.HasFlag(ExitCodes.DateFromError))
sb.Append("Zły format daty początkowej \n");
if (exitCodeFlags.HasFlag(ExitCodes.DateToError))
sb.Append("Zły format daty końcowej \n");
if (exitCodeFlags.HasFlag(ExitCodes.LibraryError))
sb.Append("Błąd wewnętrzny biblotek \n");
if (exitCodeFlags.HasFlag(ExitCodes.WrongConnectionData))
sb.Append("Złe dane połączenia \n");
ip.Report(exitCodeFlags == ExitCodes.Success
? new Tuple<string, int?, bool>("Proces pobierania zakończył sie sukcesem", 100, false)
: new Tuple<string, int?, bool>("Proces pobierania zakończył sie błędnie \n" + sb, 100, true));
}
};
process.Start();
process.BeginOutputReadLine();
process.WaitForExit();
I'm stuck and I'm looking for some ideas what can cause the problem. I'd be very thankful for any suggestions.
Thanks in advance