[chronojump/execute-process: 2/5] Splits the ExecuteProcess.run() method in two: one shows the error, the other returns it.
- From: Carles Pina i Estany <carlespina src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump/execute-process: 2/5] Splits the ExecuteProcess.run() method in two: one shows the error, the other returns it.
- Date: Tue, 4 Oct 2016 22:26:03 +0000 (UTC)
commit f41242e0c4ce5df0c2ee2a333318ec3a66b1a64c
Author: Carles Pina i Estany <carles pina cat>
Date: Tue Oct 4 23:42:53 2016 +0200
Splits the ExecuteProcess.run() method in two: one shows the error, the other returns it.
This will help using the method when we just want to show the error.
Fixes other small issues (a parenthesis, etc.)
src/chronojumpImporter.cs | 4 ++--
src/executeProcess.cs | 25 ++++++++++++++++++++++---
2 files changed, 24 insertions(+), 5 deletions(-)
---
diff --git a/src/chronojumpImporter.cs b/src/chronojumpImporter.cs
index 68bbff8..d516a28 100644
--- a/src/chronojumpImporter.cs
+++ b/src/chronojumpImporter.cs
@@ -97,7 +97,7 @@ class ChronojumpImporter
List<string> parameters = new List<string> ();
parameters.Add ("--source");
- parameters.Add (sourceFile));
+ parameters.Add (sourceFile);
parameters.Add ("--destination");
parameters.Add (destinationFile);
parameters.Add ("--source_session");
@@ -164,7 +164,7 @@ class ChronojumpImporter
importer_executable = System.IO.Path.Combine (Util.GetPrefixDir (),
"bin\\chronojump-importer\\chronojump_importer.exe");
} else {
importer_executable = "python"; // chronojump_importer works on Python 2 and
Python 3
- importer_script_path = CommandLineEncoder.EncodeArgText (System.IO.Path.Combine
(Util.GetPrefixDir (), "bin/chronojump_importer.py"));
+ importer_script_path = System.IO.Path.Combine (Util.GetPrefixDir (),
"bin/chronojump_importer.py");
}
parameters.Insert (0, importer_script_path);
diff --git a/src/executeProcess.cs b/src/executeProcess.cs
index a276210..36ba52b 100644
--- a/src/executeProcess.cs
+++ b/src/executeProcess.cs
@@ -28,7 +28,9 @@ class ExecuteProcess
{
public struct Result
{
- // Encapsulates the result of a run: stdout, stderr, exitCode (-1 if process couldn't start),
+ public const int ERROR_CANT_START = -1;
+
+ // Encapsulates the result of a run: stdout, stderr, exitCode if process couldn't start is
ERROR_CANT_START),
// success (if exitCode != 0) and errorMessage to be shown to the user.
public string stdout;
public string stderr;
@@ -49,9 +51,26 @@ class ExecuteProcess
}
};
+ public static string runShowError(string file_name, List<string> parameters)
+ {
+ Result result = run(file_name, parameters);
+
+ if (result.exitCode == Result.ERROR_CANT_START) {
+ new DialogMessage (Constants.MessageTypes.WARNING, result.errorMessage);
+ return "";
+ } else {
+ return result.allOutput;
+ }
+ }
+
+ public static Result run(string file_name, List<string> parameters)
+ {
+ return runDo (file_name, parameters);
+ }
+
// 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.
- public static Result run(string file_name, List<string> parameters)
+ private static Result runDo(string file_name, List<string> parameters)
{
Process process = new Process();
ProcessStartInfo processStartInfo = new ProcessStartInfo();
@@ -89,7 +108,7 @@ class ExecuteProcess
"{2}"),
processStartInfo.FileName, parameters_string,
e.Message);
LogB.Warning (errorMessage);
- return new Result ("", "", -1, errorMessage);
+ return new Result ("", "", Result.ERROR_CANT_START, errorMessage);
}
string stdout = process.StandardOutput.ReadToEnd();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]