缘起:公司最近的给了个对接任务,需要将用户输入Japanese 转换为 Romaji,因此用到了开源库Kakasi.NET.Interop,在通过IIS调试该库的过程中,出现了进程被无端结束,经咨询,IIS不能直接调用该库,会导致该库中一些重要文件无法被关联到一起,从而致使当前进程被结束,下面这是回复的内容:
/* IMPORTANT:
The native libkakasi.dll library will look for these 2 dictionary files:
itaijidict
kanwadict
When running as a web application, the search path used by the library will be the same as the
running host process (e.g: iisexpress.exe, w3wp.exe) and not the path of the running web application.
If it can't find any one of these file, the library will exit the running process, which is far from ideal.
It's possible to set 2 environment variables that the native library will use instead of the executing path.
KANWADICTPATH for the full path to the dictionary file: kanwadict
ITAIJIDICTPATH for the full path to the dictionary file: itaijidict
Make sure these variables are set in the running host process otherwise it won't work and any call to
the native library will kill the running process.
*/
通过配置环境变量的方法未验证,而是采取另一种执行命令行的方式去解决,解决思路如下:
1.更改Kakasi.NET.Interop项目为控制台应用程序,并添加主函数入口,通过将参数注入主函数中
2.翻译注入主函数中的参数,并保存入文件
3.读取文件内容
需要注意的地方:在执行cd命令时注意盘符问题,以及传参问题
string cmd =@"C:&cd C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC&vcvarsall.bat";
string cmd =@"D:&cd D:\Program Files (x86)\Microsoft Visual Studio 10.0\VC&vcvarsall.bat";
string cmd = @"D:&cd D:\Program Files (x86)\Kakasi.NET.Interop\bin&Kakasi.NET.Interop.exe args1 args2";
参考资料:
C#程序调用cmd.exe执行命令