代码之家  ›  专栏  ›  技术社区  ›  CodexArcanum

是否可以用其他东西替换cmd?

  •  3
  • CodexArcanum  · 技术社区  · 14 年前

    我从来没有学习过OSE,所以如果这听起来很简单或者很愚蠢,请原谅我,但是我很好奇是否有人可以替换Windows中的cmd提示。我并不是要那些真正能做到这一点的程序,因为我环顾四周,并没有真正看到任何程序。

    我要问的是1)是否真的可以编写一个全新的程序,它的行为类似于cmd,2)是否可以用它替换cmd,假设它至少可以执行cmd所做的所有工作。

    因为看起来,甚至那些声称升级了它的程序(cygwin、powershell等)实际上也在同一个小黑窗口中运行。也许我只是不完全理解cmd是如何适应Windows的整体,或者像bash这样的东西是如何连接到Linux的。

    有人愿意指引我走正确的方向吗?

    4 回复  |  直到 12 年前
        1
  •  4
  •   cHao    14 年前

        3
  •  1
  •   THE DOCTOR    14 年前

    ProcessStartInfo CmdReplacement = new System.Diagnostics.ProcessStartInfo();
    
    //choose a name and then arguments that you want to send to the command prompt
    CmdReplacement.FileName = @"C:\testfile.bat";
    CmdReplacement.Arguments = "1 2 3 4";
    
    //if you use this property it will prevent a console window from popping up
    pi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
    
    //create new process and set starting information
    System.Diagnostics.Process p = new System.Diagnostics.Process();
    p.StartInfo = CmdReplacement;
    
    
    //set this to tell you when the process has completed
    p.EnableRaisingEvents = true;
    
    p.Start();
    
    //wait until the process has completed
    while(!p.HasExited)
    {
    System.Threading.Thread.Sleep(1000);
    }
    
    //check to see what the exit code was
    if(p.ExitCode != 0)
    {
    //some error occurred
    }
    
        4
  •  0
  •   John Saunders    14 年前