0

I am struggling to make this work. Below is a quick test I am running but it does not kick off .net core exe.

I've published the .net core exe here as a single file and output type as windows exe. If I run it on the command line, it works and creates logs etc..

    var startInfo = new ProcessStartInfo(@"C:\Dev\Console.exe")
            {
                CreateNoWindow = true,
                ErrorDialog = false,
                UseShellExecute = false,
                RedirectStandardOutput = true,
                Arguments = "2019-08-29 25",
                WorkingDirectory = @"C:\Dev\"

            };

            try
            {
                var process = Process.Start(startInfo);

                var standardOutput = process.StandardOutput;
                process.WaitForExit();

                var output = standardOutput.ReadToEnd();

                Debug.WriteLine("Output: " + output);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
            }
Pavel Anikhouski
  • 21,776
  • 12
  • 51
  • 66
Otake
  • 874
  • 3
  • 8
  • 21
  • Have you tried getting your code to start a .NET exe instead of a .NET Core exe? – Andrew Morton Oct 03 '19 at 09:40
  • Yes, it runs other .net exes fine. – Otake Oct 03 '19 at 09:46
  • Could you name it something other than "Console"? I am wondering if there is a problem related to the one noted in the answer to [Console.Write in .Net Core](https://stackoverflow.com/a/49062490/1115360). – Andrew Morton Oct 03 '19 at 09:58
  • 1
    it is a different name, just changed on the example as per the company policy. – Otake Oct 03 '19 at 10:03
  • 1
    I made a "Hello World" "Press Enter to finish" console app using .NET Core. I copied your code into a .NET Framework C# console app (modifying only the program name and path) and ran it (by pressing F5). Although I saw nothing immediately, I was able to kill the .NET Core app in Task Manager, so your code finished, and I saw the console app output in the Debug messages. Do you see your "Console.exe" running in Task Manager? – Andrew Morton Oct 03 '19 at 10:09
  • 1
    You can safely assume it did manage to "kick off" the .exe file if you did not get an exception. Use Task Manager > Processes tab to see this. The standard reason for it not *seeming* to run is deadlock. As is quite likely to happen with this code, the program cannot make progress when you don't read its output. So it can't terminate and make WaitForExit() complete. – Hans Passant Oct 03 '19 at 11:53
  • @Andrew and Hans, Thanks for the comments. I am seeing conhost.exe when the line executes for process to be started. I realized both appsettings.json and log4net.config were missing and adding those I can confirm that it is running. – Otake Oct 03 '19 at 14:16

1 Answers1

0

I realized both appsettings.json and log4net.config were missing and adding those I can confirm that it is running. I think I assumed after I published .net core app through VS 2019 these would have been added but they were not.

Otake
  • 874
  • 3
  • 8
  • 21