У меня есть метод здесь, хотя я хотел бы передать вывод из него в файл, например. output.txt, как я могу сделать это в этом контексте?
foreach (string tmpLine in File.ReadAllLines(@"c:\filename.txt")) { if (File.Exists(tmpLine)) { //output } }
Обычно в командной строке вы делаете
mycommand > somefile.txt
или
mycommand | more
Это работает, потому что вывод записывается в стандартный вывод.
Вы можете попробовать http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput.aspx
Вот и все:
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();