Process.Start and redirect to text file / pipe another process

When you want to spawn a process, but want the process to dump to a text file you might use :

Process.Start("cmd.exe", "/c foo.exe -arg >" + dumpDir + "\\foo_arg.txt");

In case you don't need the file "foo_arg.txt" itself but want the actual output its possible to set ProcessStartInfo.RedirectStandardOutput flag to true and then read the process output using Process.StandardOutput stream.

Another option is to use Process Start for piping the output of the first process to the second :

Process.Start("cmd.exe", "/c foo.exe -arg " + "| bar.exe");



  • Not actually a pipe, more of a redirect. A pipe would connect it to another process.

    Process.Start("cmd.exe", "/c foo.exe -arg |" + "bar.exe");

  • Thanks Mark for your comment, i've changed the post.

  • I used Process.Start("Notepad") in my ASP.NET web app but it just shows in Task Manager, but doesn't really display/show the window. WHt is the solution?

    thanks in advance!

  • Hi guys, i have to do this, and i can´t make it work, with 2500.
    I have to compress a file with winrar, for instance c:\test\1.txt, then the original file gets deleted. For this the rar command is: rar.exe m -ri1 -ep "c:\test\1".rar "c:\test\1".txt
    I want to do this from using process.start()
    Process.Start("c:\rar.exe", "-ri1 -ep")
    But i can´t get it to work, something to do with how i pass the parameters. I have on a variable total=c:\test\1.rar c:\test\1.txt
    But i dont know how to make it all work.
    Can anyone help me please?

  • hi this is tarang i want to redirect the output of cmd.exe to vb program .i know one way i.e store the output in text file then read that file but i dont want that way

  • Add a space before the "-r1 -p", which looks like
    " -r1 -p". Most parameters needs a space in front of them.

  • Excellent post.

    Allowed me to use:
    pSign.StartInfo.FileName = "cmd.exe";
    pSign.StartInfo.Arguments = "/c echo \"ola\" | openssl dgst -sha1 -sign prikeyofs.pem " + "| openssl enc -base64";

    Thank you very much.

Comments have been disabled for this content.