Call Java code from C#

I'm stuck on one thing i can't get solved. I have part of code, which is executed from command line like a charm. Works without any problem.

So, i will to try to call this command (same) out from C#.

That's the code i'm run from commandline.

java -Xincgc -Xmx1024m -cp "%APPDATA%.minecraft\bin\minecraft.jar;%APPDATA%.minecraft\bin\lwjgl.jar;%APPDATA%.minecraft\bin\lwjgl_util.jar;%APPDATA%.minecraft\bin\jinput.jar" -Djava.library.path="%APPDATA%.minecraft\bin\natives" net.minecraft.client.Minecraft "NAME"

The part i'm trying to get it in C# looks like:

proc.StartInfo.FileName = "java";
proc.StartInfo.Arguments = "-Xincgc -Xmx1024m -cp \"%APPDATA%\\.minecraft\\bin\\minecraft.jar;%APPDATA%\\.minecraft\\bin\\lwjgl.jar;%APPDATA%\\.minecraft\\bin\\lwjgl_util.jar;%APPDATA%\\.minecraft\\bin\\jinput.jar\" -Djava.library.path=\"%APPDATA%\\.minecraft\\bin\\natives\" net.minecraft.client.Minecraft \"NAME\"";
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = false;

But, nothing happens at all. Is there something i'm doing wrong? Thanks for any help!


Expand the environment variables in the Arguments using Environment.ExpandEnvironmentVariables.

string args = "-Xincgc -Xmx1024m -cp \"%APPDATA%\\.minecraft\\bin\\minecraft.jar;%APPDATA%\\.minecraft\\bin\\lwjgl.jar;%APPDATA%\\.minecraft\\bin\\lwjgl_util.jar;%APPDATA%\\.minecraft\\bin\\jinput.jar\" -Djava.library.path=\"%APPDATA%\\.minecraft\\bin\\natives\" net.minecraft.client.Minecraft \"NAME\"";
proc.StartInfo.Arguments = Environment.ExpandEnvironmentVariables(args);

BTW - you can use a verbatim string literal to make that argument string more readable.

@"-Xincgc -Xmx1024m -cp ""%APPDATA%\.minecraft\bin\minecraft.jar;%APPDATA%\.minecraft\bin\lwjgl.jar;%APPDATA%\.minecraft\bin\lwjgl_util.jar;%APPDATA%\.minecraft\bin\jinput.jar"" -Djava.library.path=""%APPDATA%\.minecraft\bin\natives"" net.minecraft.client.Minecraft ""NAME""";

Need Your Help

Keep MySQL files as 'per-project'?

mysql svn

Currently I work at two places - at work and at home. I have a problem with keeping up to date. With files I solved my problem (I use private SVN and commit from phpStorm), but I still have no idea...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.