I have wrote simple command to do a basic echo on Linux.
This is command I want to do:
/bin/bash -c 'echo hello'
This is app I am running:
using System;
using System.Diagnostics;
namespace ProcessTest
{
class Program
{
static void Main(string[] args)
{
var startInfo = new ProcessStartInfo
{
FileName = @"/bin/bash",
Arguments = @"-c 'echo hello'",
RedirectStandardOutput = true,
UseShellExecute = false
};
using (var process = new Process { StartInfo = startInfo })
{
process.Start();
string result = process.StandardOutput.ReadToEnd();
process.WaitForExit();
Console.WriteLine(result);
Console.Read();
}
}
}
}
Instead of outputting "hello" it outputs this:
hello': -c: line 0: unexpected EOF while looking for matching `''
hello': -c: line 1: syntax error: unexpected end of file
Why is it not working?
Using double quotes works. For some reason it is just single quotes that cause this issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With