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



commit 36424ec483c6711601c9b9a094ac402dbf808bcb
Author: Xavier de Blas <xaviblas gmail com>
Date:   Thu Feb 7 18:44:50 2019 +0100

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

 src/chronojump.cs         |  2 +-
 src/chronojumpImporter.cs |  2 +-
 src/executeProcess.cs     | 32 ++++++++++++++++++--------------
 src/gui/chronojump.cs     |  2 +-
 src/gui/forceSensor.cs    |  2 +-
 src/networks.cs           |  4 ++--
 src/webcamFfmpeg.cs       | 10 ++++++----
 src/webcamMplayer.cs      |  6 +++---
 8 files changed, 33 insertions(+), 27 deletions(-)
---
diff --git a/src/chronojump.cs b/src/chronojump.cs
index 497362a8..c2800414 100644
--- a/src/chronojump.cs
+++ b/src/chronojump.cs
@@ -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);
diff --git a/src/chronojumpImporter.cs b/src/chronojumpImporter.cs
index 83874a9a..91c2d997 100644
--- a/src/chronojumpImporter.cs
+++ b/src/chronojumpImporter.cs
@@ -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
diff --git a/src/executeProcess.cs b/src/executeProcess.cs
index 52d3d87c..d051bf1c 100644
--- a/src/executeProcess.cs
+++ b/src/executeProcess.cs
@@ -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.");
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index a450214e..90a642b6 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -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.");
        }
 
diff --git a/src/gui/forceSensor.cs b/src/gui/forceSensor.cs
index 64e3b1b7..80c4b5c7 100644
--- a/src/gui/forceSensor.cs
+++ b/src/gui/forceSensor.cs
@@ -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;
diff --git a/src/networks.cs b/src/networks.cs
index 3e7dde9e..a490e783 100644
--- a/src/networks.cs
+++ b/src/networks.cs
@@ -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);
        }
 
diff --git a/src/webcamFfmpeg.cs b/src/webcamFfmpeg.cs
index a84f5229..f5aae18f 100644
--- a/src/webcamFfmpeg.cs
+++ b/src/webcamFfmpeg.cs
@@ -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);
diff --git a/src/webcamMplayer.cs b/src/webcamMplayer.cs
index 956b3383..b63512a4 100644
--- a/src/webcamMplayer.cs
+++ b/src/webcamMplayer.cs
@@ -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;
        }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]