作者KENyroj (难得一身鸡蛋糕...)
看板C_Sharp
标题[问题] 请问 C# 的执行指令结果... ??
时间Wed Jan 9 10:19:16 2008
我想要写一支程式, 利用外部指令来取得指令的执行结果...
public static string ExecuteCommand(string Command)
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = "/c " + Command;
p.StartInfo.UseShellExecute = false; //关闭Shell的使用
p.StartInfo.RedirectStandardInput = true; //重定向标准输入
p.StartInfo.RedirectStandardOutput = true; //重定向标准输出
p.StartInfo.RedirectStandardError = true; //重定向错误输出
p.StartInfo.CreateNoWindow = true; //设置不显示窗口
p.Start(); //启动
return p.StandardOutput.ReadToEnd();
}
然後我就可以 string Result = ExecuteCommand("dir C:\");
因为它呼叫的是 cmd.exe 所以它的DIR的结果就会是中文的...
可是我希望它的结果是英文的...
我知道还有一个叫 command.com 也是 DOS视窗... 而且是全英文...
但是我把那个 cmd.exe 改成 command.com 就没办法执行..
请问有没有人可以指点一下... ^^"
__yroj
--
因为不是每个人都有女朋友
所以上帝赐给我们十根手指头
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 60.248.5.97
1F:推 shinywong:你的 Comments 基本上可以不用写... 01/09 18:17