简体   繁体   English

从MATLAB调用的C .exe文件中存在的fprintf()不起作用

[英]fprintf() present in a C .exe file called from MATLAB doesn't work

I'm calling a C executable compiled using Cygwin in MATLAB, using the unix() function. 我正在使用unix()函数调用在MATLAB中使用Cygwin编译的C可执行文件。 This works fine, and I can see the desired output on the MATLAB command window. 这工作正常,我可以在MATLAB命令窗口中看到所需的输出。 However, there is an fprintf() inside the executable that is supposed to create and write to a text file which does not run - no such file is created. 但是,可执行文件中有一个fprintf()可以创建并写入无法运行的文本文件-不会创建此类文件。 The text file is created just fine when I run the executable directly through Cygwin. 当我直接通过Cygwin运行可执行文件时,就可以很好地创建文本文件。

I was wondering if I need to grant permissions to the MATLAB file/executable to enable this? 我想知道是否需要授予对MATLAB文件/可执行文件的权限才能启用此功能? How could I go about this? 我该怎么办?

What path are you using to create the file? 您使用什么路径来创建文件? It might have been created -- just not where you expected it. 它可能已经创建了-而不是您期望的那样。

If it's a relative path, you could use getcwd(2) inside your C program to get and print the working directory (or eg getpid(2) to get the PID and then do ls -d /proc/<pid>/cwd , which will work on Linux at least). 如果是相对路径,则可以在C程序内使用getcwd(2)来获取并打印工作目录(或例如getpid(2)来获取PID,然后执行ls -d /proc/<pid>/cwd ,至少可以在Linux上使用)。 Once you have the working directory, check if the file is somewhere in there. 有了工作目录后,检查文件是否在其中。

If it looks like the file really isn't being created, my next step would be to add some error checking to functions and print messages for errors to try to figure out what's going on. 如果看起来确实不是在创建文件,那么我的下一步就是向函数添加一些错误检查,并打印错误消息以尝试找出正在发生的情况。 strerror(3) and perror(3) might come in handy. strerror(3)perror(3)可能派上用场。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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