My guess is that whatever is running your program is doing so from a directory to which you don't have write permissions. The fact that there is no "garden.exe.stackdump" file gives that as a clue.
When you save it to a file, are you saving it as fopen("myfile","w")
or are you using a fully qualified name? For example, let's say that the file you want to save is called "foobar.png" and you want to save it to the directory you named below, you'd have something like:
char fname[256] = "foobar.png";
char directory[256] = "C:/Users/Joel/Desktop/garden/snaps";
char path[256];
memset(path, 0, sizeof(path));
strcpy(path, directory);
strcat(path, "/");
strcat(path, fname);
if ((fp = fopen(path, "w")) == NULL) {
fprintf(stderr, "Failed to open %s: %s\n", path, strerror(errno));
exit(1);
}
fwrite(yourdata, yourdata_size, 1, fp);
Since your program also seems to dump errors to a file as well, you might do well to chdir("/home/myname")
at the start of your program so that any ".stackdump" files get placed where you have access.
The other thing you might want to take into account is that your task scheduler may be running your script as nobody
or some other permissions-deprived account. If that's the case, you'll want to use a full path in fopen
and chdir
to a globally writable area (such as /tmp
) or a working directory with open permissions. For example:
mkdir /home/myname/scratch
chmod a+rwx /home/myname/scratch
chmod a+x /home/myname
(You set the execute bit on your home directory so that the permission-less program can get access to its subdirectory even though it can't read anything in it.)