[chronojump] ExectuteProcess run can redirect stdin
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] ExectuteProcess run can redirect stdin
- Date: Fri, 19 Jul 2019 09:49:09 +0000 (UTC)
commit a068c55a1a9cc30b10dd2b757bf1d5e2ed1e9874
Author: Xavier de Blas <xaviblas gmail com>
Date: Fri Jul 19 11:47:00 2019 +0200
ExectuteProcess run can redirect stdin
src/executeProcess.cs | 25 +++++++++++++++++++++----
1 file changed, 21 insertions(+), 4 deletions(-)
---
diff --git a/src/executeProcess.cs b/src/executeProcess.cs
index 3caffbbd..6c545816 100644
--- a/src/executeProcess.cs
+++ b/src/executeProcess.cs
@@ -67,16 +67,21 @@ class ExecuteProcess
public static Result run(string file_name, bool redirectOutput, bool redirectStderr)
{
- return runDo (file_name, new List<string>(), redirectOutput, redirectStderr);
+ return runDo (file_name, new List<string>(), "", redirectOutput, redirectStderr);
}
public static Result run(string file_name, List<string> parameters, bool redirectOutput, bool
redirectStderr)
{
- return runDo (file_name, parameters, redirectOutput, redirectStderr);
+ return runDo (file_name, parameters, "", redirectOutput, redirectStderr);
+ }
+ public static Result run(string file_name, List<string> parameters, string redirectInputString, bool
redirectOutput, bool redirectStderr)
+ {
+ return runDo (file_name, parameters, redirectInputString, 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, bool redirectOutput, bool
redirectStderr)
+ // redirectInputString is a way to do "|" or "<", better if redirectOutput and redirectStderr are
false
+ private static Result runDo(string file_name, List<string> parameters, string redirectInputString,
bool redirectOutput, bool redirectStderr)
{
Process process = new Process();
ProcessStartInfo processStartInfo = new ProcessStartInfo();
@@ -96,7 +101,7 @@ class ExecuteProcess
processStartInfo.CreateNoWindow = true;
processStartInfo.UseShellExecute = false;
- processStartInfo.RedirectStandardInput = false;
+ processStartInfo.RedirectStandardInput = (redirectInputString != "");
processStartInfo.RedirectStandardError = redirectOutput;
processStartInfo.RedirectStandardOutput = redirectStderr;
@@ -124,6 +129,18 @@ class ExecuteProcess
if (redirectStderr)
stderr = process.StandardError.ReadToEnd ().TrimEnd ('\n');
+ if(processStartInfo.RedirectStandardInput)
+ {
+ //this does not work because it has no EOF mark
+ //process.StandardInput.WriteLine("redirectInputString");
+ //
+ //this works:
+ StreamWriter sw = process.StandardInput;
+ sw.WriteLine(redirectInputString);
+ sw.Close();
+ }
+
+
process.WaitForExit ();
if (stderr != "") {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]