-1

I am trying to run a batch file that, in turn, runs a .exe (before you ask, this is necessary). I have tried the answer to this question but the code doesn't work for me. I had been using System.Diagnostics.Process.Start("bat/directory/batname.bat");
but it didn't work; it seemed to open the file but exited it before it could run the .exe
Please help!

EDIT
The codes that I have tried are as follows:
1 - "System.Diagnostics.Process.Start("G:/Software/Games/Files/Minecraft/minecraft.bat/");"
2 -
proc.StartInfo.FileName = target;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.UseShellExecute = false;

'proc.Start();'

proc.WaitForExit
( (timeout <= 0)
? int.MaxValue : timeout * NO_MILLISECONDS_IN_A_SECOND *
NO_SECONDS_IN_A_MINUTE
);

errorMessage = proc.StandardError.ReadToEnd();
proc.WaitForExit();

outputMessage = proc.StandardOutput.ReadToEnd();
proc.WaitForExit();

I know that it is opening because the cmd appears and I see the appropriate code in it.

Community
  • 1
  • 1
  • You can even add batch files or exe into cgi scripts also from iis management – Ashish Oct 31 '14 at 04:19
  • I don't understand.. sorry for being noob; I've been doing C# for only 6 months :) – MundaneBackflip Oct 31 '14 at 04:20
  • 1
    Please be more specific. Show a complete, minimal code example that fails to work for you, and tell us _exactly_ how it "doesn't work" for you. How do you know it "opened the file"? Is there any sign that the batch itself was even found, never mind executed at all? – Peter Duniho Oct 31 '14 at 04:22
  • Check your bat file `path`. – smr5 Oct 31 '14 at 04:25
  • 1
    Can you be more specific about what happened when you tried to run the batch? Did you get an error, did a window open (and did it say anything)? Can you wrap your Process.Start line in a try block, catch any exceptions, and let us know what they are? – furkle Oct 31 '14 at 04:29
  • The `Process.Start` should have worked. we need a little more info about what went wrong. Try running that batch file in a *normal* command prompt; but from the master program's directory. Look at the output. Its likely your paths are messed up. – BradleyDotNET Oct 31 '14 at 04:54
  • The `Process.Start` does work, it runs the .bat, but then the .bat doesn't do what it was supposed to. I know the .bat isn't the problem because it works fine when I run it. – MundaneBackflip Oct 31 '14 at 08:02

1 Answers1

0

Things to consider. (keep it simple at first :))

  1. Make sure the *.bat file path is accurate. just to be sure you can check it by:

    if(File.Exists(yourBatchFilePath))

  2. You can test a simple batch file to see if your code is running. echo "What ever!" >> whatever.txt save the file as c:\myTest.bat if your code is correct, a whatever.txt file should exist in c: containing "What ever!" text.

junPac
  • 111
  • 1
  • 11