1

I have a cygwin bash scripts that works:

#!/bin/sh
cd myc
cp Stats.txt Stats.txt.cpy;
cat Stats.txt.cpy | sort -n -k1 | gawk '{sum+=$2; print $0,sum}' > Stats.txt

I want to "call" it from C#:

string cmd="myscript.sh";
System.Diagnostics.Process proc = new System.Diagnostics.Process();

System.Diagnostics.ProcessStartInfo psi =
    new System.Diagnostics.ProcessStartInfo(@"C:\Cygwin\bin\bash.exe");
psi.Arguments = cmd;
psi.WorkingDirectory = "C:\\cygwin\\home\\Moon";
psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;
psi.UseShellExecute = false;
psi.CreateNoWindow = true;
proc.StartInfo = psi;

proc.Start();
string error = proc.StandardError.ReadToEnd();
string output = proc.StandardOutput.ReadToEnd();
this.textBox1.AppendText(error);
this.textBox1.AppendText(output);

It works fine from cygwin terminal BUT from C# I get:

Input file specified two times.

I suspect this is a pipes thing - can anyone help?

Ken Kin
  • 4,503
  • 3
  • 38
  • 76
ManInMoon
  • 6,795
  • 15
  • 70
  • 133

1 Answers1

0

It was a path issue.

You need to set path in the script - otherwise it uses a different "non-cygwin" path and gets wrong commands.

ManInMoon
  • 6,795
  • 15
  • 70
  • 133