gpt4 book ai didi

c# - system() 到 c# 而不调用 cmd.exe

转载 作者:太空狗 更新时间:2023-10-29 15:12:41 27 4
gpt4 key购买 nike

如何在不调用 cmd.exe 的情况下将 system("") 转换为 C#?编辑:我需要抛出类似“dir”的东西

最佳答案

如果我正确理解了你的问题,你正在寻找 Process.Start .

查看此示例(来自文档):

// Opens urls and .html documents using Internet Explorer.
void OpenWithArguments()
{
// url's are not considered documents. They can only be opened
// by passing them as arguments.
Process.Start("IExplore.exe", "www.northwindtraders.com");

// Start a Web page using a browser associated with .html and .asp files.
Process.Start("IExplore.exe", "C:\\myPath\\myFile.htm");
Process.Start("IExplore.exe", "C:\\myPath\\myFile.asp");
}

编辑

正如您所说,您需要诸如“dir”命令之类的东西,我建议您看一下 DirectoryInfo .您可以使用它来创建自己的目录列表。例如(也来自文档):

// Create a DirectoryInfo of the directory of the files to enumerate.
DirectoryInfo DirInfo = new DirectoryInfo(@"\\archives1\library");

DateTime StartOf2009 = new DateTime(2009, 01, 01);

// LINQ query for all files created before 2009.
var files = from f in DirInfo.EnumerateFiles()
where DirInfo.CreationTimeUtc < StartOf2009
select f;

// Show results.
foreach (var f in files)
{
Console.WriteLine("{0}", f.Name);
}

关于c# - system() 到 c# 而不调用 cmd.exe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2794386/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com