简体   繁体   中英

batch file execution in c#

I am running a Java batch file from C#. If I run it by double clicking it executes successfully, but if I run it from C# code it gives exception in thread

"exception in "main" thread java.lang.noclassdeffoundError"..

what can 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);

您很可能遗漏了系统环境变量中包含的一些参数。

Try setting working directory like this

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

Also, try few other options as mentioned here,

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

尝试将以下代码添加为批处理文件的第一行。

@cd /d %~dp0

Do not use batch_process_path + "\\" + instead use Path.Combine() to make sure the path is correctly fitted with slashes.

Also read this "When UseShellExecute is true, the WorkingDirectory property specifies the location of the executable"

So set it to false.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM