Skip to content

Instantly share code, notes, and snippets.

@imba-tjd
Last active July 8, 2023 13:54
Show Gist options
  • Save imba-tjd/0a5a41df029babc6c814efe5d9296593 to your computer and use it in GitHub Desktop.
Save imba-tjd/0a5a41df029babc6c814efe5d9296593 to your computer and use it in GitHub Desktop.
A program helps pwsh to read from utf8 output.
// This program helps pwsh to read from external program output from utf8 encoding.
// Compile: bflat build xargsu2a.cs -Ot --no-debug-info --no-globalization --no-reflection --no-stacktrace-data
// License: MIT
using System;
using System.Diagnostics;
using System.Text;
if (args.Length == 0)
{
Console.Error.WriteLine("xargs utf8 to ansi:\nExample usage: xargsu2a git log > log.txt");
return;
}
var spi = new ProcessStartInfo(args[0])
{
RedirectStandardOutput = true,
StandardOutputEncoding = Encoding.UTF8,
UseShellExecute = false,
};
for (int i = 1; i < args.Length; i++)
spi.ArgumentList.Add(args[i]);
var p = Process.Start(spi);
string s = p.StandardOutput.ReadToEnd();
Console.Write(s);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment