{"record":{"id":"c3a018c4eeb52ef5","repo":"NickeManarin/ScreenToGif","slug":"output","errorCode":null,"errorMessage":"output","messagePattern":"output","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"warning","filePath":"ScreenToGif/Util/EncodingManager.cs","lineNumber":1289,"sourceCode":"                            UseShellExecute = false,\n                            CreateNoWindow = true\n                        };\n\n                        using (var process = new Process())\n                        {\n                            process.StartInfo = procStartInfo;\n                            process.Start();\n\n                            var message = await process.StandardOutput.ReadToEndAsync();\n                            var error = await process.StandardError.ReadToEndAsync();\n\n                            if (!string.IsNullOrWhiteSpace(message))\n                                output += message + Environment.NewLine;\n\n                            if (!string.IsNullOrWhiteSpace(error))\n                            {\n                                output += error + Environment.NewLine;\n                                throw new Exception(output);\n                            }\n\n                            process.WaitForExit(1000);\n                        }\n                    }\n\n                    SetCommand(id, true, command, output);\n                }\n                catch (Exception e)\n                {\n                    LogWriter.Log(e, \"It was not possible to run the post encoding command.\");\n                    SetCommand(id, false, command, output, e);\n                }\n                finally\n                {\n                    Update(id, 4, watch.Elapsed);\n                    watch.Restart();\n                }","sourceCodeStart":1271,"sourceCodeEnd":1307,"githubUrl":"https://github.com/NickeManarin/ScreenToGif/blob/a4d0a67c2131cd048ceec86cd40afc2f1a06f2fd/ScreenToGif/Util/EncodingManager.cs#L1271-L1307","documentation":"EncodingManager runs the user's preset.CustomCommands via cmd /c, captures stdout and stderr asynchronously, and if StandardError is non-whitespace, throws new Exception(output) where output is the accumulated stdout+stderr text. The exception message is therefore the raw command output, not a fixed label.","triggerScenarios":"preset.ExecuteCustomCommands && preset.CustomCommands is set, and at least one line writes to stderr. Lines are split on '\\n' and each is run as `cmd /c <line>`.","commonSituations":"User's post-encode hook script has a typo, wrong path, or missing dependency; the tool legitimately writes to stderr even on success (e.g. ffmpeg-style progress on stderr); placeholder substitution produced an invalid command; quoted path issue with {p}/{f}/{u} replacement.","solutions":["Test the custom command directly in a cmd shell with the substituted {p}/{f}/{u} values.","If the command intentionally writes to stderr, redirect stderr to nul or capture only the exit code.","Fix placeholder quoting — paths with spaces must be double-quoted in the user command.","Run the command with absolute paths rather than relying on PATH."],"exampleFix":"// before\nif (!string.IsNullOrWhiteSpace(error))\n{\n    output += error + Environment.NewLine;\n    throw new Exception(output);\n}\n\n// after\nif (!string.IsNullOrWhiteSpace(error))\n{\n    output += error + Environment.NewLine;\n    throw new Exception($\"Post-encoding command failed. Output:\\n{output}\");\n}","handlingStrategy":"validation","validationCode":"// Validate the user command parses and the executable exists before running\nforeach (var line in preset.CustomCommands.Split('\\n', StringSplitOptions.RemoveEmptyEntries))\n{\n    if (string.IsNullOrWhiteSpace(line)) continue;\n    // optionally resolve the executable on PATH and warn if missing\n}","typeGuard":"// n/a","tryCatchPattern":"try { /* run cmd /c */ }\ncatch (Exception e) when (e.Message.Contains(output))\n{ LogWriter.Log(e, \"post-encode command\"); SetCommand(id, false, command, output, e); }","preventionTips":["Use absolute paths in custom commands; do not rely on PATH.","Quote every {p}/{f}/{u} substitution to survive spaces.","Document that stderr output is treated as failure, so users redirect stderr if their tool writes to it on success."],"tags":["post-encoding","custom-command","process","shell"],"backgroundTag":null,"analyzedSha":"a4d0a67c2131cd048ceec86cd40afc2f1a06f2fd","analyzedAt":"2026-08-13T11:12:06.147Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}