0

I have an executable called outtext.exe which writes some output to console. I want to write this output directly to file in the commandline. I know I can capture the output from the Process object but now I just want to use my command as is.

I thought I could:

    Dim psi As New ProcessStartInfo
    psi.FileName = "c:\sourcefiles\test\outtest.exe"
    psi.Arguments = "> c:\outfile.txt"
    psi.UseShellExecute = False
    Process.Start(psi)

The problem is that no "outfile.txt" is created. How can I make this work?

serializer
  • 1,003
  • 2
  • 13
  • 27
  • possible duplicate of [Capturing console output from a .NET application (C#)](http://stackoverflow.com/questions/186822/capturing-console-output-from-a-net-application-c) – Daniel Hilgarth Jan 16 '13 at 11:38
  • Thank you for the answer - it is not a duplicate. – serializer Jan 16 '13 at 11:49
  • I am sure your question read differently when I marked it as duplicate. The non-existing edit log however proves that I am wrong. Sorry for being too fast and reading your question sloppily. – Daniel Hilgarth Jan 16 '13 at 11:51

1 Answers1

3

file redirection to C:\outfile.txt is a feature of the cmd process. You could try to do something like:

psi.FileName = "c:\windows\system32\cmd.exe"
psi.Arguments = "/c c:\sourcefiles\test\outtest.exe > C:\outfile.txt"
Ignacio Soler Garcia
  • 21,122
  • 31
  • 128
  • 207