You can try and use the bash invocation read and execute -c
and quoted command line (This is supposed to solve character escaping)
Process proc = new Process();
proc.StartInfo.FileName = "/bin/bash";
proc.StartInfo.Arguments = "-c 'echo p1-22=250 > /dev/servoblaster'";
proc.StartInfo.UseShellExecute = true;
proc.StartInfo.RedirectStandardOutput = false;
proc.Start();
proc.WaitForExit();
But that might not work either so try and use ProcessStartInfo
which inherently waits for everything to finish processing before exiting.
string executable = "/bin/bash";
string args = "echo p1-22=250 > /dev/servoblaster";
ProcessStartInfo procInfo = new ProcessStartInfo(executable , args);
procInfo.UseShellExecute = false;
procInfo.CreateNoWindow = true;
procInfo.RedirectStandardOutput = true;
procInfo.RedirectStandardError = true;
Process proc = System.Diagnostics.Process.Start(procInfo);
proc.WaitForExit();
int exitCode = proc.ExitCode;
proc.Close();
I had more luck with running a script file instead of running commands directly. This is most likely cause by character escaping that is required when passing args directly to bash. Making a script file with the commands inside them could solve the problem you are having.
touch servo.sh
chmod +x servo.sh
Add the commands into the script
#!/bin/bash
echo p1-22=250 > /dev/servoblaster
FileStream file = new FileInfo("/dev/servoblaster").OpenWrite(); StreamWriter write = new StreamWriter(file, Encoding.ASCII); write.Write("p1-22=50"); write.Flush();