Open new cmd from console application and write text in the new Cmd

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sreedhar82
    New Member
    • Oct 2012
    • 1

    Open new cmd from console application and write text in the new Cmd

    Hi,
    I want to open one new CMD from console application, write text into the new CMD and then coming back to the control on the old cmd. (like interactively working on the both)

    please look into the below code

    Code:
    Process P1 = Process.Start(@"C:\WINDOWS\system32\cmd.exe");
    P1.StartInfo.RedirectStandardInput = true;
    P1.StartInfo.RedirectStandardOutput = true;
    P1.StartInfo.UseShellExecute = false;
    StreamWriter wr = P1.StandardInput;
    wr.WriteLine("First line in New Cmd");
    Console.WriteLine("First line in Old Cmd");
    wr.WriteLine("Second line in New Cmd");
    Console.WriteLine("Second line in Old Cmd");
    it is giving the exception "StandardIn has not been redirected"

    Please help me on this issue
    Last edited by Meetee; Oct 23 '12, 07:21 AM. Reason: Please add code tags <code/> around your code
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    You can't start a process and then set it's StartInfo parameters. It's too late by then, you've already started the process. Also, you're redirected the output but haven't specified where.

    Comment

    Working...