I'm receiving a random line break in the following C# string and can't identify why the output is on two separate lines.
I've really only tried to define the variable in two different manners. Both produce the same results.
string cmdStr = "docker images | grep -E '^prabhasgupte/webmon.*latest' | head -1 | awk '{print $3}'";
Console.Write(cmdStr);
string imageId = commands.Bash(cmdStr);
Console.Write(imageId);
string x = $"docker tag {imageId} scan_target:{imageId}";
Console.Write(x);
This is the output I'm receiving:
docker images | grep -E '^prabhasgupte/webmon.*latest' | head -1 | awk '{print $3}'
0043699b906f
docker tag 0043699b906f
scan_target:0043699b906f
public static string Bash(this string cmd)
{
var escapedArgs = cmd.Replace("\"", "\\\"");
var process = new Process()
{
StartInfo = new ProcessStartInfo
{
FileName = "/bin/bash",
Arguments = $"-c \"{escapedArgs}\"",
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true,
}
};
process.Start();
string result = process.StandardOutput.ReadToEnd();
process.WaitForExit();
return result;
}