Commit 36424ec4 authored by Xavier de Blas's avatar Xavier de Blas

webcamFfmeg process stdout and stderr to false (avoid hangs on windows)

parent 8229b90a
......@@ -583,7 +583,7 @@ public class ChronoJump
{
LogB.Information("Finding dialout:");
string executable = "groups";
ExecuteProcess.Result execute_result = ExecuteProcess.run (executable);
ExecuteProcess.Result execute_result = ExecuteProcess.run (executable, true, true);
if(execute_result.success)
{
LogB.Information(execute_result.stdout);
......
......@@ -279,7 +279,7 @@ class ChronojumpImporter
parameters.Insert (0, importer_script_path);
}
ExecuteProcess.Result execute_result = ExecuteProcess.run (importer_executable, parameters);
ExecuteProcess.Result execute_result = ExecuteProcess.run (importer_executable, parameters, true, true);
if (execute_result.exitCode != 0) {
// Python interpretar was executed but the Python file wasn't found or the script failed
......
......@@ -56,7 +56,7 @@ class ExecuteProcess
public static Result runShowErrorIfNotStarted(string file_name, List<string> parameters)
{
Result result = run(file_name, parameters);
Result result = run(file_name, parameters, true, true);
if (result.exitCode == Result.ERROR_CANT_START) {
new DialogMessage (Constants.MessageTypes.WARNING, result.errorMessage);
......@@ -65,18 +65,18 @@ class ExecuteProcess
return result;
}
public static Result run(string file_name)
public static Result run(string file_name, bool redirectOutput, bool redirectStderr)
{
return runDo (file_name, new List<string>());
return runDo (file_name, new List<string>(), redirectOutput, redirectStderr);
}
public static Result run(string file_name, List<string> parameters)
public static Result run(string file_name, List<string> parameters, bool redirectOutput, bool redirectStderr)
{
return runDo (file_name, parameters);
return runDo (file_name, parameters, redirectOutput, redirectStderr);
}
// Executes file_name without creating a Window and without using the shell
// with the parameters. Waits that it finishes it. Returns the stdout and stderr.
private static Result runDo(string file_name, List<string> parameters)
private static Result runDo(string file_name, List<string> parameters, bool redirectOutput, bool redirectStderr)
{
Process process = new Process();
ProcessStartInfo processStartInfo = new ProcessStartInfo();
......@@ -97,8 +97,8 @@ class ExecuteProcess
processStartInfo.CreateNoWindow = true;
processStartInfo.UseShellExecute = false;
processStartInfo.RedirectStandardInput = false;
processStartInfo.RedirectStandardError = true;
processStartInfo.RedirectStandardOutput = true;
processStartInfo.RedirectStandardError = redirectOutput;
processStartInfo.RedirectStandardOutput = redirectStderr;
process.StartInfo = processStartInfo;
......@@ -117,8 +117,12 @@ class ExecuteProcess
return new Result ("", "", Result.ERROR_CANT_START, errorMessage);
}
string stdout = process.StandardOutput.ReadToEnd().TrimEnd ('\n');
string stderr = process.StandardError.ReadToEnd ().TrimEnd ('\n');
string stdout = "";
string stderr = "";
if (redirectOutput)
stdout = process.StandardOutput.ReadToEnd().TrimEnd ('\n');
if (redirectStderr)
stderr = process.StandardError.ReadToEnd ().TrimEnd ('\n');
process.WaitForExit ();
......@@ -137,7 +141,7 @@ class ExecuteProcess
* returns false if there are problems calling it
*/
public static bool RunAtBackground(ref Process process, string file_name, List<string> parameters,
bool createNoWindow, bool useShellExecute, bool redirectInput)
bool createNoWindow, bool useShellExecute, bool redirectInput, bool redirectOutput, bool redirectStderr)
{
ProcessStartInfo processStartInfo = new ProcessStartInfo();
......@@ -157,8 +161,8 @@ class ExecuteProcess
processStartInfo.CreateNoWindow = createNoWindow;
processStartInfo.UseShellExecute = useShellExecute;
processStartInfo.RedirectStandardInput = redirectInput; //note UseShellExecute has to be false to be able to redirect
processStartInfo.RedirectStandardError = true;
processStartInfo.RedirectStandardOutput = true;
processStartInfo.RedirectStandardError = redirectOutput;
processStartInfo.RedirectStandardOutput = redirectStderr;
process.StartInfo = processStartInfo;
......@@ -386,7 +390,7 @@ class ExecuteProcess
//C) call process
//ExecuteProcess.run (executable, parameters);
Result execute_result = run (executable, parameters);
Result execute_result = run (executable, parameters, true, true);
//LogB.Information("Result = " + execute_result.stdout);
LogB.Information("\n<------ Done calling R file.");
......
......@@ -6140,7 +6140,7 @@ LogB.Debug("mc finished 5");
executable = System.IO.Path.Combine(Util.GetPrefixDir(), "bin/debug.bat");
LogB.Information("Calling debug: " + executable);
ExecuteProcess.Result execute_result = ExecuteProcess.run (executable);
ExecuteProcess.Result execute_result = ExecuteProcess.run (executable, true, true);
LogB.Information("Called debug.");
}
......
......@@ -1765,7 +1765,7 @@ LogB.Information(" re R ");
LogB.Information("\nCalling slide ----->");
ExecuteProcess.Result execute_result = ExecuteProcess.run (executable, parameters);
ExecuteProcess.Result execute_result = ExecuteProcess.run (executable, parameters, true, true);
LogB.Information("\n<------ Done calling slide");
return execute_result.success;
......
......@@ -59,7 +59,7 @@ public class Networks
List<string> parameters = new List<string>();
parameters.Insert (0, "-q");
ExecuteProcess.Result execute_result = ExecuteProcess.run (executable, parameters);
ExecuteProcess.Result execute_result = ExecuteProcess.run (executable, parameters, true, true);
bool on = screenIsOn(execute_result.stdout);
LogB.Information("Screen is on?" + on.ToString());
......@@ -74,7 +74,7 @@ public class Networks
parameters.Insert (4, "on");
}
execute_result = ExecuteProcess.run (executable, parameters);
execute_result = ExecuteProcess.run (executable, parameters, true, true);
LogB.Information("Result = " + execute_result.stdout);
}
......
......@@ -24,6 +24,8 @@ using System;
using System.IO;
using System.Text.RegularExpressions; //Regex
//note the stdout and stderr redirection to false is to fix problems with windows
public class WebcamFfmpeg : Webcam
{
private UtilAll.OperatingSystems os;
......@@ -70,7 +72,7 @@ public class WebcamFfmpeg : Webcam
List<string> parameters = createParametersPlayPreview();
process = new Process();
bool success = ExecuteProcess.RunAtBackground (ref process, executable, parameters, false, false, false);
bool success = ExecuteProcess.RunAtBackground (ref process, executable, parameters, false, false, false, false, false);
if(! success)
{
process = null;
......@@ -89,7 +91,7 @@ public class WebcamFfmpeg : Webcam
List<string> parameters = createParametersPlayFile (filename);
process = new Process();
bool success = ExecuteProcess.RunAtBackground (ref process, executable, parameters, false, false, false);
bool success = ExecuteProcess.RunAtBackground (ref process, executable, parameters, false, false, false, false, false);
if(! success)
{
process = null;
......@@ -111,7 +113,7 @@ public class WebcamFfmpeg : Webcam
process = new Process();
List<string> parameters = createParametersOnlyCapture();
//List<string> parameters = createParametersCaptureAndDelayedView();
bool success = ExecuteProcess.RunAtBackground (ref process, executable, parameters, true, false, true); //redirectInput
bool success = ExecuteProcess.RunAtBackground (ref process, executable, parameters, true, false, true, false, false); //redirectInput, not output, not stderr
if(! success)
{
streamWriter = null;
......@@ -320,7 +322,7 @@ public static class WebcamFfmpegGetDevicesWindows
List<string> parameters = createParameters();
ExecuteProcess.Result execute_result = ExecuteProcess.run (executable, parameters);
ExecuteProcess.Result execute_result = ExecuteProcess.run (executable, parameters, true, true);
LogB.Information("---- stdout: ----");
LogB.Information(execute_result.stdout);
......
......@@ -71,7 +71,7 @@ public class WebcamMplayer : Webcam
parameters.Insert (i ++, "screenshot=" + Util.GetMplayerPhotoTempFileNamePre(videoDeviceToFilename()));
process = new Process();
bool success = ExecuteProcess.RunAtBackground (ref process, executable, parameters, true, false, true); //redirectInput
bool success = ExecuteProcess.RunAtBackground (ref process, executable, parameters, true, false, true, true, true); //redirectInput, redirectOutput, redirectError
if(! success)
{
streamWriter = null;
......@@ -124,7 +124,7 @@ public class WebcamMplayer : Webcam
process = new Process();
bool success = ExecuteProcess.RunAtBackground (ref process, executable, parameters, false, true, false);
bool success = ExecuteProcess.RunAtBackground (ref process, executable, parameters, false, true, false, true, true);
if(! success)
{
process = null;
......@@ -278,7 +278,7 @@ public class WebcamMplayer : Webcam
parameters.Insert (4, Util.GetMplayerPhotoTempFileNamePre(videoDeviceToFilename()) + "%04d.png");
parameters.Insert (5, Util.GetVideoTempFileName());
ExecuteProcess.Result execute_result = ExecuteProcess.run (executable, parameters);
ExecuteProcess.Result execute_result = ExecuteProcess.run (executable, parameters, true, true);
return execute_result.success;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment