首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >无法从C#执行编译的matlab可执行文件

无法从C#执行编译的matlab可执行文件
EN

Stack Overflow用户
提问于 2012-08-21 22:51:09
回答 1查看 1.1K关注 0票数 1

对于我正在开发的一个模块,我收到了一个编译好的Matlab可执行文件(注意,它是一个独立的.exe,而不是.dll或类似的东西),我必须执行它才能为我做一些分析工作。

工作流程是创建一个输入文件(普通的、简单的.csv格式),执行.exe并解析由Matlab可执行文件生成的输出文件(也是.csv)。

我已经对输入文件生成和输出文件解析进行了测试,如果我自己这么说的话,它们工作得很好。但是我在运行Matlab可执行文件时遇到了一些问题。我已经安装了正确的MCR,我可以双击可执行文件,它就会像预期的那样运行。但是使用以下代码,可执行文件就不能正确执行:

代码语言:javascript
代码运行次数:0
运行
复制
    var analyzer = new Process
    {
        StartInfo =
        {
            FileName = Path.Combine(WorkDirectory, "analyzer.exe"),
            CreateNoWindow = false,
            WindowStyle = ProcessWindowStyle.Hidden,
            UseShellExecute = false, RedirectStandardError = true, RedirectStandardOutput = true // These lines were added for debugging purposes
        }
    };
    analyzer.Start();
    punProcess.WaitForExit();
    string debuginfo = punProcess.StandardOutput.ReadToEnd();
    string debuginfo2 = punProcess.StandardError.ReadToEnd();

我从"debuginfo“中提取的文本如下:

代码语言:javascript
代码运行次数:0
运行
复制
     {Warning: Name is nonexistent or not a directory: C:\MATLAB\R2009b\toolbox\pun.} 
     {> In path at 110
        In addpath at 87
        In startup at 1} 
     {Warning: Name is nonexistent or not a directory:
     C:\MATLAB\R2009b\toolbox\pun\pun.} 
     {> In path at 110
        In addpath at 87
        In startup at 2} 

我从"debuginfo2“中提取的文本是:

代码语言:javascript
代码运行次数:0
运行
复制
     {Error using textscan
     Invalid file identifier.  Use fopen to generate a valid file identifier.

     Error in readin (line 4)

     Error in Analyzer (line 12)

     } 
     MATLAB:FileIO:InvalidFid

这些问题是由我的代码引起的吗?它们是由于通过C#使用它的上下文造成的吗?或者分析器本身可能有问题?我无法访问分析器可执行文件的源代码,因此无法调试该部分。

发生的错误,可能是因为给出的警告,以及我遗漏了某种引用(可能是对MCR的引用?)当我双击它(或者从cmd运行它,也像一个咒语)时,它是隐式可用的吗?

工作目录已签出。我可以看到输入文件是由先前的C#代码创建的,也可以看到可执行文件被复制到那里。因此,问题不是由于在正确的位置准备正确的文件时出错造成的。

干杯,Xilconic

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-08-22 17:40:08

正如Dmitriy Reznik所评论的,指定StartInfo的WorkingDirectory解决了我遇到的问题。应该是这样的:

代码语言:javascript
代码运行次数:0
运行
复制
var analyzer = new Process
{
    StartInfo =
    {
        FileName = Path.Combine(WorkDirectory, "analyzer.exe"),
        WorkingDirectory = WorkDirectory
        CreateNoWindow = false,
        WindowStyle = ProcessWindowStyle.Hidden,
        UseShellExecute = false, RedirectStandardError = true, RedirectStandardOutput = true // These lines were added for debugging purposes
    }
};
analyzer.Start();
punProcess.WaitForExit();
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12057558

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档