Ramu
Ramu

Reputation: 353

Run batch file with arguments

I'm trying to run a batch file from c#. The purpose is to create a simple file when the batch file executes. Seems its not working.

Here is the batch file code

one.bat

echo %*
copy NUL EmptyFile.txt
pause

C# Code

 System.Diagnostics.Process.Start("cmd.exe", "/c C:\\Users\ABC\\Desktop\\F1\\one.bat \"a\" b c ");

C# code runs fine and also seems like calls the bat file, but the new file in the batch file is not getting created.

Am i missing something here?

Thanks

Upvotes: 0

Views: 1877

Answers (1)

Gabriel Luci
Gabriel Luci

Reputation: 40928

You aren't specifying where EmptyFile.txt should go, so it's trying to put it in the default working directory, which happens to be Windows' system32 directory, which the process probably doesn't have access to.

You can either use a full path in your bat file (copy NUL C:\Temp\EmptyFile.txt) or change your code to use a ProcessStartInfo object and set the WorkingDirectory to whatever you want.

Upvotes: 1

Related Questions