为什么我不能通过c#programm在使用Windows控制台时查看目录 [英] Why can`t i chane the directory while using windows console via c# programm
问题描述
使用System;
使用System.Text;
使用System.Diagnostics;
使用System.IO;
公共类MyClass
{
static void Main(string [] args){
ProcessStartInfo psi = new ProcessStartInfo();
流程流程=新流程();          
    process.StartInfo.FileName =" cmd.exe";  
$
while(true){
string command = Console。 ReadLine();
 
 
    process.StartInfo.Arguments =" / c" +命令;
 
    process.StartInfo.UseShellExecute = false;
 
    process.StartInfo.RedirectStandardError = true;
    process.StartInfo.RedirectStandardOutput = true;
 
    process.StartInfo.CreateNoWindow = true;
    process.EnableRaisingEvents = true;            
跨度>  process.Start();
$
Console.WriteLine(process.StandardOutput.ReadToEnd());
< span style ="white-space:pre"> process.WaitForExit();
$
if(命令。等于("退出")){break;}
}
}}
$
如果要更改当前目录,请使用
Directory.SetCurrentDirectory 。
更改或简单获取当前目录,
目录。 GetCurrentDirectory 。
using System;
using System.Text;
using System.Diagnostics;
using System.IO;
public class MyClass
{
static void Main(string[] args){
ProcessStartInfo psi = new ProcessStartInfo();
Process process = new Process();
process.StartInfo.FileName = "cmd.exe";
while(true){
string command= Console.ReadLine();
process.StartInfo.Arguments = "/c " + command;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.CreateNoWindow = true;
process.EnableRaisingEvents = true;
process.Start();
Console.WriteLine(process.StandardOutput.ReadToEnd());
process.WaitForExit();
if(command.Equals("quit")){break;}
}
}}
If you want to change the current directory, use Directory.SetCurrentDirectory.
Change it back or simply get the current directory, Directory.GetCurrentDirectory.
这篇关于为什么我不能通过c#programm在使用Windows控制台时查看目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!