I play Terraria. I host games sometimes. I want users to be able to grab a current map of my world, whenever they want to. So I created a simple web page to use MoreTerra (a mapping software) to create a map in the background for me and a web page to display the map to users.
MoreTerra comes with a batch file that runs itself from the command line. the batchfile contains the following:
@ECHO OFF
cmd.exe /c MoreTerra.exe %1 %2 %3 %4
@ECHO ON
I want to execute this when a user clicks a button on my web page, so I created the following code:
try
{
string worldFile = "\"" + AppSettings.GetAppSetting("WorldFile", false) + "\"";
string outputLocation = "\"" + AppSettings.GetAppSetting("OutputLocation", false) + @"\" + AppSettings.GetAppSetting("ImageFileName", false) + "\"";
string fileName = AppSettings.GetAppSetting("MT_Location", false) + @"\" + "MoreTerraNoGui.bat";
ProcessStartInfo si = new ProcessStartInfo();
si.FileName = @"C:\Windows\SysWOW64\cmd.exe";
si.Arguments = "/c " + fileName + " -w " + worldFile + " -o " + outputLocation;
si.WorkingDirectory = AppSettings.GetAppSetting("MT_Location", false);
si.CreateNoWindow = true;
si.WindowStyle = ProcessWindowStyle.Hidden;
si.UseShellExecute = false;
si.RedirectStandardOutput = true;
si.RedirectStandardError = true;
Log.WriteToLog(ProjectLogType, "btnRefresh_Click", si.Arguments, LogEnum.Debug);
Process subProcess = Process.Start(si);
subProcess.WaitForExit();
string output = subProcess.StandardOutput.ReadToEnd();
string error = subProcess.StandardError.ReadToEnd();
Log.WriteToLog(ProjectLogType, "btnRefresh_Click", output, LogEnum.Debug);
Log.WriteToLog(ProjectLogType, "btnRefresh_Click", error, LogEnum.Debug);
}
catch(Exception x)
{
Log.WriteToLog(ProjectLogType, "btnRefresh_Click", x, LogEnum.Critical);
}
So far it hasn't really done anything. In the Task Manager, I can see Console Window Host process start and stop in less than a second every time I click the button, but no image is generated. The Output and Error variables are always empty. but when I debug and break at "subProcess.WaitForExit();" I can see this error in the Locals Window in Visual Studio
- MainModule 'subProcess.MainModule' threw an exception of type 'System.ComponentModel.Win32Exception' System.Diagnostics.ProcessModule {System.ComponentModel.Win32Exception}
+ base {"A 32 bit processes cannot access modules of a 64 bit process."} System.Runtime.InteropServices.ExternalException {System.ComponentModel.Win32Exception}
NativeErrorCode 299 int
I've tried using the same cmd.exe in both the C# code and in the batch file, both x86, and x64, but to no avail.
I used corflags.exe to check MoreTerra.exe, and it's not 32bit required, my code is compiled for AnyCPU, so I'm at a real loss.
I've been scouring the internet, but everything I've found is incorporated into the above code.
Any help would be greatly appreciated. TIA