我有以下代码来读取和重写gawk到文本文件的输出(而不是使用shell-execute并使用public class FloatNanConverter : JsonConverter
{
public override bool CanConvert(Type objectType)
{
return objectType == typeof(float) || objectType == typeof(float?);
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null)
return null;
var value = JValue.Load(reader);
if (objectType == typeof(float?))
return (float?)value;
else
return (float)value;
}
public override bool CanWrite { get { false; } }
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
throw new NotImplementedException();
}
}
执行此操作):
>
之后检查var processStartInfo = new ProcessStartInfo
{
FileName = "gawk.exe",
Arguments = $@"-F ""{separator}"" -f ""{scriptFullFileName}"" ""{inputFullFileName}""",
UseShellExecute = false,
WorkingDirectory = workingDirectory,
RedirectStandardOutput = true,
CreateNoWindow = true
};
using (var process = Process.Start(processStartInfo))
{
using (var streamReader = process.StandardOutput)
{
var result = streamReader.ReadToEnd();
}
}
,它始终以以下行开头:
fstat< 0:fd = 0
fstat< 0:fd = 2
从shell执行 gawk.exe ,这些行不存在。
我做错了什么 - 或者更好的是,如果没有额外的解析,我怎么能摆脱这两行呢?