Running bat script c #

I am trying to run a batch script package as part of a sharp program, the code I use is shown below:

 Process proc = new Process();
 proc.StartInfo.FileName = "G:\\Media\\Downloads\\print.bat";
 proc.Start();

The script is simple (for testing purposes) and contains one line:

echo hello > output.txt

When I run the script from Windows Explorer, it works, but does not execute when run from C # code.

any thoughts?

Also, how can I give processes a callback method when it's done?

thank

+3
source share
1 answer

It works great for me. I assume it happens that when executing a batch file programmatically, you expect the output file to be created in a folder Downloadswhen it is actually created in the application folder

- , , :

proc.StartInfo.WorkingDirectory = @"G:\Media\Downloads\";

, , WaitForExit Exited Process.

+7

Source: https://habr.com/ru/post/1771086/


All Articles