给定一个包含以下行的文本文件helloworld.txt:
您好/世界
以下sed
命令将输出删除了行的文件内容:
sed '\:^hello/world:d' helloworld.txt
但是,如果该命令作为System.Diagnostics.Process运行:
var process = new Process
{
StartInfo =
{
FileName = "sed",
Arguments = "'\\:^hello/world:d' helloworld.txt",
RedirectStandardOutput = true,
UseShellExecute = false
}
};
process.Start();
while (!process.StandardOutput.EndOfStream)
{
Console.WriteLine(process.StandardOutput.ReadLine());
}
process.WaitForExit();
然后输出为“hello / world”(即不删除匹配行)。
为什么会这样?