Run Command Prompt Commands

前端 未结 14 1901
暖寄归人
暖寄归人 2020-11-21 05:32

Is there any way to run command prompt commands from within a C# application? If so how would I do the following:

copy /b Image1.jpg + Archive.rar Image2.jp         


        
14条回答
  •  清酒与你
    2020-11-21 06:26

    You can achieve this by using the following method (as mentioned in other answers):

    strCmdText = "'/C some command";
    Process.Start("CMD.exe", strCmdText);
    

    When I tried the methods listed above I found that my custom command did not work using the syntax of some of the answers above.

    I found out more complex commands need to be encapsulated in quotes to work:

    string strCmdText;
    strCmdText = "'/C cd " + path + " && composer update && composer install -o'";
    Process.Start("CMD.exe", strCmdText);
    

提交回复
热议问题