0
votes

I'm calling a C executable compiled using Cygwin in MATLAB, using the unix() function. This works fine, and I can see the desired output on the MATLAB command window. 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. The text file is created just fine when I run the executable directly through Cygwin.

I was wondering if I need to grant permissions to the MATLAB file/executable to enable this? How could I go about this?

1
are you using absolute file path to open/create the file? - lonstud
I was using a relative path and that was the issue. Silly of me not to try that first. Thanks! - prestojunkie

1 Answers

2
votes

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 e.g. getpid(2) to get the PID and then do ls -d /proc/<pid>/cwd, which will work on Linux at least). 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.