I'm trying to execute a batch file in C# but i'm not getting any luck doing it.
I've found multiple examples on the internet doing it but it is not working for me.
The command string contains the name of the batch file (stored in system32) and some files it should manipulate. (Example: txtmanipulator file1.txt file2.txt file3.txt) When I execute the batch file manually it works correctly.
When executing the code it gives me an ExitCode: 1 (Catchall for genral errors)
What am I doing wrong? Thanks in advance!
| ||
add comment | ||
15
|
This should work. You could try to dump out the contents of the output and error streams in order to find out what's happening:
* EDIT *
Given the extra information in your comment below I was able to recreate the problem. There seems to be some security setting that results in this behaviour (haven't investigated that in detail).
This does work if the bat file is not located in c:\windows\system32. Try moving it to some other location, e.g. the location of your executable. Note that keeping custom bat files or executables in the Windows directory is bad practice anyway.
| ||||||||||||||||||||||||||
|
10
|
this simple line will execute the batch file.
| ||||||||
1
|
After some great help from steinar this is what worked for me:
Thanks Steinar!
| ||
add comment |
0
|
It works fine. I tested it like this:
I commented out turning off the window so I could SEE it run.
|
command
is. If it contains paths with spaces, you 'll need to put quotes around them.– Jon Apr 1 '11 at 22:01