Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 用C语言将输出管道化为文本文件#_C#_.net_Windows - Fatal编程技术网

C# 用C语言将输出管道化为文本文件#

C# 用C语言将输出管道化为文本文件#,c#,.net,windows,C#,.net,Windows,我在这里有一个方法,虽然我想通过管道将输出从它传输到一个文件,例如output.txt,但在这种情况下,我如何做到这一点 foreach (string tmpLine in File.ReadAllLines(@"c:\filename.txt")) { if (File.Exists(tmpLine)) { //output } } 就是这样: var file = File.AppendText(@"c:\output.txt"); fo

我在这里有一个方法,虽然我想通过管道将输出从它传输到一个文件,例如output.txt,但在这种情况下,我如何做到这一点

  foreach (string tmpLine in File.ReadAllLines(@"c:\filename.txt"))
  {
    if (File.Exists(tmpLine))
    {
      //output
    }
  }
就是这样:

var file = File.AppendText(@"c:\output.txt");

foreach (string tmpLine in File.ReadAllLines(@"c:\filename.txt"))
{
    if (File.Exists(tmpLine))
    {       
        file.WriteLine(tmpLine);
    }
}

file.Close();
就是这样:

var file = File.AppendText(@"c:\output.txt");

foreach (string tmpLine in File.ReadAllLines(@"c:\filename.txt"))
{
    if (File.Exists(tmpLine))
    {       
        file.WriteLine(tmpLine);
    }
}

file.Close();

通常,在命令行方面,您可以这样做

mycommand > somefile.txt

这是因为输出被写入std out


您可以尝试正常的命令行方式,您可以这样做

mycommand > somefile.txt

这是因为输出被写入std out


您可以尝试

更好的方法,当然是在
文件
上使用
。当然,更好的方法是在
文件
上使用
块。