我正在开发一个项目,我希望在运行我的脚本时启动一个控制台窗口并向客户端显示一些顶级输出。我遵循这种方法并且能够启动cmd但无法写入它:
public class ConsoleOutput {
ProcessStartInfo psi;
Process p;
public ConsoleOutput()
{
psi = new ProcessStartInfo("cmd.exe")
{
RedirectStandardError = true,
RedirectStandardInput = true,
RedirectStandardOutput = true,
UseShellExecute = false,
Arguments = "/k",
};
p = Process.Start(psi);
}
public void writeMessage(string msg)
{
StreamWriter sw = p.StandardInput;
sw.WriteLine("prompt " + msg);
}
}