I am trying to manipulate my swagger doc. I need to run redoc split to separate the main swagger.
During start.cs I am getting the swagger doc and saving it to the file system. That works as expected. Then in my split method, I get the swagger doc and run it through redoc split and nothing happens, no error and no messages. I put breakpoints on the first line, inside the Try block and when I step, it exits so I think an error is getting swallowed somewhere.
I can run this from a command window just fine.
public static void RunSplitCommand()
{
string output = string.Empty;
string error = string.Empty;
var args = "redocly split \"../bin/swagger/Swagger.json\" --outDir= \"../bin/swagger\"";
using (var process = new System.Diagnostics.Process())
{
process.StartInfo = new System.Diagnostics.ProcessStartInfo();
process.StartInfo.WorkingDirectory = Directory.GetCurrentDirectory();
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.Arguments = args;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
try
{
process.Start();
process.WaitForExit();
if (process.StandardOutput.ReadToEnd() != string.Empty)
output = process.StandardOutput.ReadToEnd();
else if (process.StandardError.ReadToEnd() != string.Empty)
output = process.StandardError.ReadToEnd();
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
string.Concat(output, "\n");
}
process.StartInfo.FileName = "redocly.exe";instead (and pass your args).redocly? A batch? Surely it's an actual application stored somewhere. You don't needcmd.exeto run something and get itsstdoutput. Any CLI application can be used. It's a common mistake to go viacmd.exejust because it's "command line something something"process.StandardOutput.ReadToEnd()twice, without resetting the stream position. Either callprocess.StandardOutput.Seek(0, SeekOrigin.Begin)before the second call, or better use pattern matching:else if (process.StandardError.ReadToEnd() is { } errorString) { output = errorString; }