我正在研究ILOG,它是从IBM开发的。ILOG程序可以通过cmd控制台运行,如下所示:
oplrun -p C:\Users\pc_copat\opl\santez\"workName"
当我将上面的代码写到cmd控制台屏幕上时,程序没有出错。不过,当我在c#中使用这些代码时,如下所示,它不起作用。
`string komut = @"oplrun -p C:\Users\pc_copat\opl\santez\ " + '\u0022' + calismaAdi + '\u0022';`
ProcessStartInfo startInfo = new ProcessStartInfo();
//startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.FileName = "cmd.exe";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.Arguments = "/K "+komut;
try
{
// Start the process with the info we specified.
// Call WaitForExit and then the using-statement will close.
using (Process exeProcess = Process.Start(startInfo))
{
exeProcess.WaitForExit();
}
}
catch
{
// Log error.
}我总是会犯这样的错误:
“‘oplrun”不被识别为内部或外部命令、可操作的程序或批处理文件。
我怎样才能解决这个问题?
发布于 2016-07-11 01:14:47
您可以使用StandardInput.WriteLine在cmd上执行命令,而不是传递参数。
string komut = @"oplrun -p C:\Users\pc_copat\opl\santez\ " + '\u0022' + calismaAdi + '\u0022';
ProcessStartInfo startInfo = new ProcessStartInfo();
//startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.FileName = "cmd.exe";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
//startInfo.Arguments = "/K "+komut;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardInput = true;
string currentFolderString = AppDomain.CurrentDomain.BaseDirectory; // Not sure if this will work but it should be your directory containing the oplrun.exe
try
{
// Start the process with the info we specified.
// Call WaitForExit and then the using-statement will close.
using (Process exeProcess = Process.Start(startInfo))
{
exeProcess.StandardInput.WriteLine(string.format("cd \"{0}\"", currentFolderString)); // navigate to the oplrun.exe directory
exeProcess.StandardInput.WriteLine(komut); // execute komut instead of as param
exeProcess.WaitForExit();
}
}
catch
{
// Log error.
}https://stackoverflow.com/questions/38297757
复制相似问题