CMD c#窗口应用程序

本文关键字:应用程序 窗口 CMD | 更新日期: 2023-09-27 18:17:42

我需要从CMD运行一些东西。在c#窗口

ProcessStartInfo info = new ProcessStartInfo("cmd.exe");
//info.Arguments = "/K control /name Microsoft.DevicesAndPrinters";
info.Arguments = @"/K cd ../../../../FilesMigration/Solution/FilesMigration/bin/Debug ";
Process.Start(info);

它确实启动cmd并转到指定的位置,但现在我需要运行"fileMigration.exe"及其参数。

我试过了:

info.Arguments = "/K filesmigration '"Data Source=(local)/SQLExpress;Initial Catalog=FilesMigration;Integrated Security=true; Connection Timeout=30'""
                          + " '"C:/Programing/api/PE_API_Tester/FilesMigration/SCD File System/For Ella/K_Root'""
                          + " '"C:/Programing/api/PE_API_Tester/FilesMigration/SCD File System/For Ella/U_Root_Analysis_Clusters'""
                          + " '"C:/Programing/api/PE_API_Tester/FilesMigration/SCD File System/For Ella/U_Root_Analysis_Flows'""
                          + " '"C:/Programing/api/PE_API_Tester/FilesMigration/SCD File System/For Ella/U_Root_AtpSoftware_MatrixAtp'""
                          + " '"notepad'""
                          + " '"CO1'""
                          + " '"V1'"";
Process.Start(info);

但它似乎在旧位置搜索。我试了"控制台"。写"also",但它没有做任何事情。

知道怎么写正确吗?

CMD c#窗口应用程序

尝试设置WorkingDirectory属性,而不是自己传递命令

ProcessStartInfo info = new ProcessStartInfo("cmd.exe");
info.WorkingDirectory = @"../../../../FilesMigration/Solution/FilesMigration/bin/Debug ";
info.Arguments = "/K filesmigration ......";
Process.Start(info);

请在链接中查看当UseShellExecute为false时该属性的不同行为

您可以使用ProcessStartInfo.WorkingDirectory属性从选定位置运行命令。

要一次运行多个命令,您可以创建批处理文件(*.bat或*.cmd),然后运行此批处理文件