Skip to content

Instantly share code, notes, and snippets.

@Teut2711
Created July 15, 2020 07:45
Show Gist options
  • Save Teut2711/9dde6b3098acceabf5e231776b195d10 to your computer and use it in GitHub Desktop.
Save Teut2711/9dde6b3098acceabf5e231776b195d10 to your computer and use it in GitHub Desktop.
public async Task<IActionResult> OnPostAsync(string opt, string value)
{
ProcessStartInfo start = new ProcessStartInfo();
start.FileName = "python/python-3.8.0-embed-amd64/python.exe";
start.Verb = "runas";
start.Arguments = $"python/backend.py {opt} {value}";
start.UseShellExecute = false;
start.RedirectStandardOutput = true;
using (Process process = Process.Start(start))
{
using (System.IO.StreamReader reader = process.StandardOutput)
{
dynamic result = JObject.Parse(reader.ReadToEnd());
var stream = new FileStream(result.path, FileMode.Open);
var fileName = "document.pdf";
var mimeType = "application/pdf";
if (result.status == "Success")
{
stream =
return new FileStreamResult(stream, mimeType)
{
FileDownloadName = fileName;
};
}
else if (result.status == "ErrorDNE")
{
}
else if (result.status == "ErrorMRE")
{
}
Console.WriteLine(result);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment