I have a .net core application and I created a process to run my .bat file which includes commands for a python script extracting gabor features from a video. I want to hold the program until python code finishes(until all features are extracted)
I want to fully extact featues before I return to View(info).However, instead of waiting for the python script, code directly goes to return statment
public async Task<IActionResult> ShowVideo(VideoInfo info)
{
info.name = info.url;
string path = "/videos/" info.url;
info.url = path;
info.possibleVideoList = GenerateVideoDropDown();
await ExtractFramesAndGenerateSubtitles(info);
return View(info);
}
public async Task ExtractFramesAndGenerateSubtitles(VideoInfo info)
{
string videPath = Path.Combine(Environment.WebRootPath, "videos/") info.name;
var outputPath = "frames";
string pathName = info.possibleVideoList[info.name];
//Move file to the correct location so the Gabor feature extraction code can use
ChangeFileNameAndMove(videPath);
// TODO: Can be deleted later
//Exctract frames
GenerateFrames(pathName, outputPath);
//Run the Gabor feature extraction
ExecuteCommandSync("runGabor.bat");
}
public async Task ExecuteCommandSync(object command)
{
var timeoutSignal = new CancellationTokenSource(TimeSpan.FromSeconds(10));
System.Diagnostics.ProcessStartInfo procStartInfo =
new System.Diagnostics.ProcessStartInfo("cmd.exe", "/c " command);
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
procStartInfo.CreateNoWindow = false;
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo = procStartInfo;
//proc.Start();
if (proc.Start())
{
proc.EnableRaisingEvents = true;
proc.BeginOutputReadLine();
proc.BeginErrorReadLine();
await proc.WaitForExitAsync(timeoutSignal.Token);
//allow std out to be flushed
await Task.Delay(100);
}
// Get the output into a string
string result = proc.StandardOutput.ReadToEnd();
}
CodePudding user response:
Add await
before your "ExecuteCommandSync("runGabor.bat");"
like below :
await ExecuteCommandSync("runGabor.bat");