예제 #1
0
 private static void ProcessOutputLine(string type, string line, PhotoProcessResult status)
 {
     if (string.IsNullOrWhiteSpace(line))
     {
         return;
     }
     Startup.EphemeralLog($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] {type}: {line}", false);
     if (type == "stderr")
     {
         if ((line.Contains("it/s") || line.Contains("s/it")) && line.Trim().EndsWith("]"))
         {
             // not an error, process wrongly logging success status to stderr
         }
         else
         {
             status.ErrorCount++;
             status.Errors.Add(line);
         }
     }
 }
예제 #2
0
        public PhotoProcessResult Execute(string inputFolder, string configFilename = null)
        {
            var output  = new StringBuilder();
            var status  = new PhotoProcessResult();
            var process = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName = @"cmd.exe",
                    RedirectStandardInput  = true,
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true,
                    CreateNoWindow         = true
                },
                EnableRaisingEvents = true
            };

            process.ErrorDataReceived += new DataReceivedEventHandler(delegate(object sender, DataReceivedEventArgs e)
            {
                if (!string.IsNullOrEmpty(e.Data))
                {
                    ProcessOutputLine("stderr", e.Data, status);
                }
            });
            process.OutputDataReceived += new DataReceivedEventHandler(delegate(object sender, DataReceivedEventArgs e)
            {
                if (!string.IsNullOrEmpty(e.Data))
                {
                    ProcessOutputLine("stdout", e.Data, status);
                }
            });
            process.Start();
            process.BeginOutputReadLine();
            process.BeginErrorReadLine();

            var command = @$ "python -m main";

            if (!string.IsNullOrEmpty(configFilename))
            {
                command += " --config " + configFilename;
            }

            using (var sw = process.StandardInput)
            {
                if (sw.BaseStream.CanWrite)
                {
                    sw.WriteLine(Anaconda_Activate_Script);

                    // TODO: Remove this
                    /* DEBUG */
                    //sw.WriteLine(@"python -c ""import vispy; print(vispy.sys_info()); """);
                    //sw.WriteLine(@"python -c ""import time; print('waiting 10 secs'); time.sleep(10); print('done');""");
                    /* /DEBUG */

                    sw.WriteLine(@$ "CD " "{Inpainting_AppDir}" "");
                    sw.WriteLine(command);
                    sw.WriteLine("conda deactivate");
                }
            }
            WaitOrKill(process, 30, command);
            status.OutputFolder = inputFolder;
            status.ExitCode     = process.ExitCode;
            return(status);
        }