gpt4 book ai didi

c# - Process.StandardOutput.ReadToEnd() 和无关的换行符

转载 作者:可可西里 更新时间:2023-11-01 10:27:22 25 4
gpt4 key购买 nike

我试图理解为什么当我调用上述函数时,我在读取的输出中每第 80 列得到十六进制 0D0A。

我有一个 powershell 脚本,为了简洁起见,其中有两行用于测试:

$xmlSpew = "<IISAppPoolConfig><DefaultWebSite><ApplicationPoolName>DefaultAppPool</ApplicationPoolName></DefaultWebSite><AuthN>Basic</AuthN></IISAppPoolConfig>"
Write-Output $xmlSpew

我正在使用带有 ProcessStartInfo 的 Process 对象调用脚本,如下所示:

var psi = new ProcessStartInfo
{
WorkingDirectory = Path.GetDirectoryName(FileToRun),
FileName = FileToRun,
Arguments = Arguments,
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardError = true,
RedirectStandardOutput = true,
};

var process = new Process
{
StartInfo = psi,
EnableRaisingEvents = true,
};

FileToRun 值为:

C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe

参数值为:

-File "C:\Program Files\MyTest\MyProgInputs\read.d\IISAppPoolConfig.ps1"

脚本运行良好,我返回退出代码 0,但我在标准输出中每 80 个字符就有一个神秘的(对我来说)0D0A 换行符,我使用以下方法捕获:

var Stdout = new List<string>;

...

Stdout.Add(process.StandardOutput.ReadToEnd());

一旦我将标准输出存储在字符串 var 中,这就会对我的 XML 工作造成严重破坏。我希望得到我在 ps1 脚本中写入标准输出的确切内容,而不是额外的换行符。

我错过了什么?我找过其他有这个问题的人,但我没有找到答案。希望不是我受到搜索挑战。

最佳答案

关注this P/Invoke 方法并将 dwXCountChars 设置为一个非常大的值。不要忘记在标志中也包含 STARTF_USECOUNTCHARS

关于c# - Process.StandardOutput.ReadToEnd() 和无关的换行符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11295922/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com