2011-01-29 3 views
0

입력 및 출력을 파일로 리디렉션 할 수 있습니까? 내가 나의 프로그램을 실행하면입력 출력을 stdout 대신 파일로 리디렉션하는 방법은 무엇입니까?

예 : -

abc.exe <input.txt> output.txt 

그것은 input.txt을 입력을 읽고 출력이 사전 :

+5

대답은 의문입니다. 그래서 ... 여기에 무엇이 묻고 있습니까? –

+0

@BlueRaja - Danny Pflughoeft : 저는 C#으로 할 수 있는지 몰랐습니다. 나는 리눅스를 가지고있어서 C#에서 같은 것을 찾고 있었다. 기본적으로 사용할 수 있는지 몰랐습니다.). – TCM

+0

Cheng :이 질문은 C#과 아무 관련이 없습니다. 이것은 입력 리다이렉션이 Windows와 Linux에서 모두 작동하는 방식입니다 (OS에서 처리됩니다). http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/redirection.mspx?mfr=true –

답변

3

이 뜻입니까?

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 

namespace ConsoleApplication1 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      String s; 
      while ((s = Console.In.ReadLine())!= null) 
      { 
       Console.Out.WriteLine(s); 
      } 
     } 
    } 
} 
+0

Console.WriteLine 및 Console.ReadLine을 사용하고있었습니다. – TCM

0

시스템에

감사를 OUTPUT.TXT을 작성해야합니다. Console.SetIn (TextReader newIn)

System.Console.SetOut (TextWriter newOut)

프로그램 실행 중에 출력을 다양하게하려면 좋을 것입니다.

0

입출력을 리디렉션>를 < 가진 콘솔 애플리케이션을 호출하고. 프로그램에서 Console.Read 또는 ReadLine과 Write, WriteLine 등을 사용하기 만하면됩니다.

관련 문제