1

I successfully can run an anylogic model using a standalone java application and I run a .bat file without any problem on my windows 10.

this is the image of run description in this case; enter image description here

but when I call the same .bat file through c# application, the run log description differs from start and the model does not run. the image of run log description is:

enter image description here

in first image after the directory, java.exe file is called and then -cp command is called. but in second image after directory -cp command is called immediately. And the model does not run as well. what is wrong and what should I do to solve the problem?

P.s. the code of calling batch file is as follows:

try      
{
       ProcessStartInfo procInfo = new ProcessStartInfo();
       procInfo.UseShellExecute = true;
       procInfo.FileName = @"directory and file.bat";  //The file in that DIR.
       procInfo.WorkingDirectory = @"dirctory"; //The working DIR.
       procInfo.Verb = "runas";
       Process.Start(procInfo);  //Start that process.
}
catch (Exception ex)
{
   MessageBox.Show(ex.Message.ToString());
}

1 Answers1

1

This a common problem with .bat launcher on corporate systems as it expects java to be in a certain location. I would advise to edit the .bat file and replace %PATH_XJAL% used in the command to launch the model with just 'java' - this usually works as java will be somewhere in the system PATH variable.

Artem P.
  • 816
  • 1
  • 6
  • 8
  • 1
    This is the most obvious/common explanation for the errors in his second screenshot, but not for why running the same *whole* script from Windows directly or C# gives different results (though answer accepted so maybe the question is missing some key detail....). Plus at least the last few versions of AnyLogic now produce batch scripts which fall back to a default `java` invocation if it can't find a JRE in places it looks for it, so that should no longer be necessary unless the export was done by an old version of AnyLogic. – Stuart Rossiter Oct 15 '21 at 15:44