Windows命令行 [英] Windows Command Line

查看:103
本文介绍了Windows命令行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好



我在家里很无聊所以我决定制作一个windows命令行的副本。好吧,我已经完成了,但我想对我的代码提出第二意见。



这里是我的代码:



  static  StreamReader sr =  null ; 

静态 void Main( string [] args)
{
StreamWriter sw = null ;
ProcessStartInfo startInfo = new ProcessStartInfo( cmd );
处理cmd = Process();

startInfo.UseShellExecute = false ;
startInfo.RedirectStandardInput = true ;
startInfo.RedirectStandardOutput = true ;
startInfo.CreateNoWindow = true ;

cmd.StartInfo = startInfo;
cmd.Start();
sr = cmd.StandardOutput;
sw = cmd.StandardInput;
Thread cmdOutput = new 线程( new ThreadStart(输出));
cmdOutput.Start();

string comand = ;
do
{
comand = Console.ReadLine();
sw.WriteLine(comand);
} while (comand!= 退出);

cmdOutput.Abort();
cmd.Close();

}

静态 void output()
{
StreamReader _sr = sr;
while (_sr.Peek()!= 0
{
Console.Write(( char )_ sr.Read());
}
}

}





请告诉我你的意见。

解决方案

看看这篇文章,了解它是如何完成的:命令提示符控制 [ ^ ]

Hello

I was boring here in home so i''ve decided to make a replica of the windows command line. Well, i have done it but i want a second opinion for my code.

here is my code:

static StreamReader sr = null;

        static void Main(string[] args)
        {            
            StreamWriter sw = null;           
            ProcessStartInfo startInfo = new ProcessStartInfo("cmd");
            Process cmd = new Process();
           
            startInfo.UseShellExecute = false;
            startInfo.RedirectStandardInput = true;
            startInfo.RedirectStandardOutput = true;
            startInfo.CreateNoWindow = true;
            
            cmd.StartInfo = startInfo;            
            cmd.Start();
            sr = cmd.StandardOutput;
            sw = cmd.StandardInput;
            Thread cmdOutput = new Thread(new ThreadStart(output));
            cmdOutput.Start();
            
            string comand = "";
            do
            {
                comand = Console.ReadLine();
                sw.WriteLine(comand);                
            } while (comand != "exit");

            cmdOutput.Abort();
            cmd.Close();                   
                        
        }

        static void output()
        {
            StreamReader _sr = sr;
            while (_sr.Peek() != 0)
            {
                Console.Write((char)_sr.Read());
            }
        }        

    }



So tell me your opinion.

解决方案

Take a look at this article to see how it is done : Command Prompt Control[^]


这篇关于Windows命令行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆