Batch file execution in C #

I am running a Java batch file from C #. If I run it with a double click, it will succeed, but if I run it from C # code, it will give an exception in the thread

"exception in the" main "topic java.lang.NoClassDefFoundError" ..

what could be the reason and how can it be solved? I am using the code:

var si = new ProcessStartInfo();

si.CreateNoWindow = true;
si.FileName = "batch-file path";
si.UseShellExecute = true;

Process.Start(si);
+3
source share
4 answers

Most likely, you are missing some parameters that will be included in the variables of your system environment.

+1
source

Try setting up your working directory as follows

process.StartInfo.WorkingDirectory = "C:\";

Also, try a few other options mentioned here,

http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/20992653-dabf-4b31-85f7-e7bfbfb4557c

0

.

@cd /d %~dp0
0

Do not use batch_process_path + "\" + instead use Path.Combine () to make sure the path is set correctly by a slash.

Also read this "When UseShellExecute is true, the WorkDirectory property indicates the location of the executable

Therefore set the value to false.

0
source

All Articles