Calling Batch File From C#

后端 未结 2 983
被撕碎了的回忆
被撕碎了的回忆 2021-02-20 10:36

I am hoping that this is an easy question, but i have the following code in my C# application and for some reason it will not execute the batch file I am pointing to.

         


        
2条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-20 11:29

    This should work

    System.Diagnostics.Process proc = new System.Diagnostics.Process();
    proc.StartInfo.FileName = "C:\\Watcher\\Cleanup.bat";
    proc.StartInfo.WorkingDirectory = "C:\\Watcher";
    proc.Start();
    

    You need to set the WorkingDirectory otherwise the command will be executed in what is the current directory of the calling application

提交回复
热议问题