0

I am trying to preserve the input line at the bottom of powershell, but do not know how.

This is what I am doing. It builds on this SO post.

using System.Diagnostics;

public static class ConsoleApplication
{
    static void process_Exited(object sender, EventArgs e)
    {
        //Console.WriteLine(string.Format("process exited with code {0}\n", /*process.ExitCode.ToString()*/));
        Console.WriteLine("Exited");
    }

    static void process_ErrorDataReceived(object sender, DataReceivedEventArgs e)
    {
        Console.WriteLine(e.Data);
    }

    static void process_OutputDataReceived(object sender, DataReceivedEventArgs e)
    {
        Console.WriteLine(e.Data);
    }

    public static void Main(string[] args)
    {
        Process process = new Process();

        process.EnableRaisingEvents = true;
        process.OutputDataReceived += new System.Diagnostics.DataReceivedEventHandler(process_OutputDataReceived);
        process.ErrorDataReceived += new System.Diagnostics.DataReceivedEventHandler(process_ErrorDataReceived);
        process.Exited += new System.EventHandler(process_Exited);

        //process.StartInfo.FileName = "cmd.exe";
        process.StartInfo.FileName = "powershell.exe";
        //process.StartInfo.Arguments = "/c ver";
        process.StartInfo.UseShellExecute = false;
        process.StartInfo.RedirectStandardOutput = true;
        //process.StartInfo.RedirectStandardInput = true;
        process.StartInfo.RedirectStandardError = true;
        process.Start();

        process.BeginOutputReadLine();
        process.WaitForExit();
    }
}

I expect the following when I type hello

Windows PowerShell Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

PS C:\Users\MyUser>hello

Instead I get

Windows PowerShell Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

hello

Can I preserve the bottom input prefix?

I eventually want to use this over ssh and would like to maintain the directory path prefix.

Water
  • 3,245
  • 3
  • 28
  • 58

0 Answers0