I was not completely sure if this's place is really in the beginner section, but my feeling is that I'm missing something obvious here that everybody else knows.
I have Debian 9 with LXDE.
I wrote a simple program and compiled it for Windows with mingw.
When testing the program I discovered that if I run the program by double clicking it (wrich opens it in Wine) then the current working directory was my home directory (instead of the directory where the exe is located and where it was clicked from the file manager).
I prepared a simple test program:
Code: Select all
#include <stdio.h>
#include <unistd.h>
int main (int argc, char **argv){
char cwd[1024];
FILE* file;
getcwd(cwd, sizeof(cwd));
file=fopen("Z:\\b\\pro\\cwdtest\\cwd.txt","w");
if (file != NULL) {
fprintf(file,"%s\n",cwd);
fclose (file);
}
printf("%s\n",cwd);
}
Some context: file is cwdwin.c in directory /b/pro/cwdtest and my home directory is /b
compiled with
Code: Select all
b@balt3:~/pro/cwdtest$ i686-w64-mingw32-g++ -o cwdwin.exe cwdwin.c
b@balt3:~/pro/cwdtest$
Once from the command line:
Code: Select all
b@balt3:~/pro/cwdtest$ wine cwdwin.exe
Z:\b\pro\cwdtest
b@balt3:~/pro/cwdtest$
and once by double-clicking cwdwin.exe from the file manager in directory /b/pro/cwdtest and the CWD was "Z:\b".
So it is true: When I run the program from command line the CWD is the directory from where I call it but if I click it from file manager CWD is my home directory.
Why is it like this?
How can I change it?
I wanted to find out if the problem is with Wine or with the file manager.
A very simple test: prepare a similar test program but this time compile it natively and not for windows.
I made:
Code: Select all
#include <stdio.h>
#include <unistd.h>
int main (int argc, char **argv){
char cwd[1024];
FILE* file;
getcwd(cwd, sizeof(cwd));
file=fopen("/b/pro/cwdtest/cwd.txt","w");
if (file != NULL) {
fprintf(file,"%s\n",cwd);
fclose (file);
}
printf("%s\n",cwd);
}
Code: Select all
b@balt3:~/pro/cwdtest$ g++ -o cwd cwd.c
b@balt3:~/pro/cwdtest$
Code: Select all
b@balt3:~/pro/cwdtest$ ./cwd
/b/pro/cwdtest
b@balt3:~/pro/cwdtest$
I tried to run it by double clicking it from the file manager but I couldn't.
I detected another problem:
I'm not able to run native programs by double clicking on them. Not only this one but any program too.
When I click it it just asks me what program to open it with. And apparently it says that this is a "shared library" and not an executable file
(but it is an executable program and the execute bit is set). In Debian Wheezy I was able to run all programs by clicking them. On Stretch I can't.
I can run executable #! scripts, however. After clicking it says it's an executable script and I can chose to run or open it or cancel. Similar window appeared in Wheezy when clicking executable programs.
But here it thinks it's a shared library and doesn't give me this choice which is annoying.
Is this a MIME problem?
How do I solve it?
So because of this additional problem I was unable to determine if my original problem is fault of Wine or file manager.
So my actual problems are:
1. Why if I run Wine programs from file manager then CWD is set to my home directory? How to fix this?
2. Why I can't run normal programs from file manager? How to fix this?
I'll just add that this is a relatively recently installed system and so far only things I did with it was moving home directory from /home/b to /b, instaling some packets from the package manager, browsing some internet and writing some programs so there is low probability that I broke this by myself by some stupid actions.
Thanks in advance and please tell me if I have to provide additional information.