0

I want to run bat file on using System.Diagnostics and I did. But I have a problem.

public static void RunMiningProgram(string appPath, string batFilePath)
{
    for (int i = 0; i < 2; i++)
    {
        using (Process p = new Process())
        {
            p.StartInfo.FileName = $"{appPath}\\{batFilePath}";
            p.StartInfo.WorkingDirectory = appPath;
            p.Start();
        }
    }
}
var path = @"D:\PROJECTS\ies-disk\asp-net-core\IesDisk.ApiProcess\wwwroot\C.bat";
var appath = @"D:\PROJECTS\ies-disk\asp-net-core\IesDisk.ApiProcess\wwwroot";

RunMiningProgram(apppath, path);

enter image description here

When we run the program, the results of the bat files appear on the console screen that Kestrel opens. How can I open two different cmd applications instead of showing them in the Kestrel console.

if i visualize my question i want two different cmd screens to open.

enter image description here

jamesnet214
  • 1,044
  • 13
  • 21
Burak Ergün
  • 63
  • 1
  • 8
  • You'll probably need to start new command prompts. Take a look at this question https://stackoverflow.com/questions/36776854/running-a-cmd-command-from-c-sharp – phuzi Jun 16 '21 at 12:11
  • you do not want to see it on screen (probably this is an issue for sure) ? what is the issue ? – Aristos Jun 16 '21 at 12:13
  • The issue is when I run the bat file using ```process.start(batfilepath)```. it is not opening a new cmd screen. But I want to it. – Burak Ergün Jun 16 '21 at 12:15
  • @BurakErgün probably its open it, but under the account of asp.net - remember this is server side programming - and who is going to monitor this commands on server ? – Aristos Jun 16 '21 at 12:17

1 Answers1

1
public static void RunMiningProgram(string appPath, string batFilePath)
{
    for (int i = 0; i < 2; i++)
    {
        Process.Start("cmd.exe", $"/c start /D {appPath} {appPath}{batFilePath}");
    }
}

static void Main(string[] args)
{
    RunMiningProgram("C:\\", "hello.bat");
}
3m3sd1
  • 128
  • 8
  • ```$"/c start /D {appPath} {appPath}{batFilePath}"```.What's for ```/D ``` – Burak Ergün Jun 16 '21 at 12:53
  • @Burak specifying working directory I think. Check cmd start documentation. It let's you not have to specify it by setting p.StartInfo.WorkingDirectory – 3m3sd1 Jun 16 '21 at 12:57