ok i'm desperate and kan't find an answer. Does anyone know how 2 get the directory of the programming currently running. ie, fubar (the app) is stored in /usr/bin i do: cd / fubar output should be "/usr/bin" how would i do this. I've tried everything i can think of and everything in my books and i still can't get it to work. btw it's in c -- To unsubscribe send e-mail to suse-linux-e-unsubscribe@suse.com For additional commands send e-mail to suse-linux-e-help@suse.com Also check the FAQ at http://www.suse.com/Support/Doku/FAQ/
First, I think you might have a misunderstanding of the Linux (and Unix) file system as well as C. First, argv[0] contains the name of the file as it was typed. If /usr/bin is in your path, and your program is /usr/bin/fubar argv[0] will contain fubar if you typed fubar. Also, remember that in Linux, files do not reside in directories. The directory entry is just a pointer to the inode. An old Unix technique is to create hard links to a single file. For instance, /bin/vi, /bin/view, /bin/ex would all be hard links to the same file. So if you types the view command, you would access the file in view (read only) mode. jason wrote:
ok i'm desperate and kan't find an answer.
Does anyone know how 2 get the directory of the programming currently running . ie, fubar (the app) is stored in /usr/bin i do: cd / fubar
output should be "/usr/bin"
how would i do this. I've tried everything i can think of and everything in my books and i still can't get it to work. btw it's in c
-- To unsubscribe send e-mail to suse-linux-e-unsubscribe@suse.com For additional commands send e-mail to suse-linux-e-help@suse.com
Also check the FAQ at http://www.suse.com/Support/Doku/FAQ/
--
Jerry Feldman
If I understand what you want, there is a function called getcwd, (GET
Current Working Directory) that does what you want. (see program
at end) It is not ANSI standard C. It works with SuSE 6.1, YMMV.
I've installed additional libraries and upgraded a few. I suspect it
is available on most systems.
HTH,
Jeffrey
Quoting jason
ok i'm desperate and kan't find an answer.
Does anyone know how 2 get the directory of the programming currently running. ie, fubar (the app) is stored in /usr/bin i do: cd / fubar
output should be "/usr/bin"
how would i do this. I've tried everything i can think of and everything in my books and i still can't get it to work. btw it's in c
============================= cut here =============================
#include
getcwd() isn't what i'm needing. I'll just describe what the program is.
The program will be used to students to handin homework assigments over the
network. the program handin will be in ~user/bin, the conf files will be in
~user/handin/conf and the students assignments will be stored in
~user/handin/assign#/user_id. They will issue the command by typing
"~coursenumber/bin/handin
If I understand what you want, there is a function called getcwd, (GET Current Working Directory) that does what you want. (see program at end) It is not ANSI standard C. It works with SuSE 6.1, YMMV. I've installed additional libraries and upgraded a few. I suspect it is available on most systems.
HTH, Jeffrey
-- To unsubscribe send e-mail to suse-linux-e-unsubscribe@suse.com For additional commands send e-mail to suse-linux-e-help@suse.com Also check the FAQ at http://www.suse.com/Support/Doku/FAQ/
chdir("~class") does not work because ~class is a bash convention.
Try chdir("/home/class") or whatever is appropriate directory. (Note:
I haven't tried this, it is very late and I need some sleep.)
If the home directory varies depending on the machine, ask your
sysadmin why. As an alternative, try extracting it from the finger
output or getting the finger source and see how it does it. I don't
use NIS, so this may not work on your system.
HTH,
Jeffrey
Quoting jason
getcwd() isn't what i'm needing. I'll just describe what the program is.
The program will be used to students to handin homework assigments over the network. the program handin will be in ~user/bin, the conf files will be in ~user/handin/conf and the students assignments will be stored in ~user/handin/assign#/user_id. They will issue the command by typing "~coursenumber/bin/handin
<files>" so if you can see, the cwd will be the students dir and i need to change to the class dir. That is my problems since i kan't get from the students directory to the class directory. chdir( "~class") doesn't work and searching the passwd file for the classes home directory won't work since the computers use a NIS server.
-- To unsubscribe send e-mail to suse-linux-e-unsubscribe@suse.com For additional commands send e-mail to suse-linux-e-help@suse.com Also check the FAQ at http://www.suse.com/Support/Doku/FAQ/
After exchaning email with Jason, what he wants to do is to change directory to the current user's home directory. That can be done very easily with: uid = getuid(); pwd = getpwuid(uid); if (pwd) { chdir(pwd->pw_dir); } The password structure contains the user's home directory in pw_dir. On 2 Apr 2000, at 23:10, Jeffrey Taylor wrote:
If I understand what you want, there is a function called getcwd, (GET Current Working Directory) that does what you want. (see program at end) It is not ANSI standard C. It works with SuSE 6.1, YMMV. I've installed additional libraries and upgraded a few. I suspect it is available on most systems.
HTH, Jeffrey
Quoting jason
: ok i'm desperate and kan't find an answer.
Does anyone know how 2 get the directory of the programming currently running. ie, fubar (the app) is stored in /usr/bin i do: cd / fubar
output should be "/usr/bin"
how would i do this. I've tried everything i can think of and everything in my books and i still can't get it to work. btw it's in c
============================= cut here ============================= #include
int main(int argc, char *argv[]) { printf("%s\n", getcwd()); }
-- To unsubscribe send e-mail to suse-linux-e-unsubscribe@suse.com For additional commands send e-mail to suse-linux-e-help@suse.com Also check the FAQ at http://www.suse.com/Support/Doku/FAQ/
-- Jerry Feldman Contractor, eInfrastructure Partner Engineering 508-467-4315 http://www.testdrive.compaq.com/linux/ Compaq Computer Corp. 200 Forest Street MRO1-3/F1 Marlboro, Ma. 01752 -- To unsubscribe send e-mail to suse-linux-e-unsubscribe@suse.com For additional commands send e-mail to suse-linux-e-help@suse.com Also check the FAQ at http://www.suse.com/Support/Doku/FAQ/
participants (4)
-
gaf@gaf.ne.mediaone.net
-
Gerry.Feldman@compaq.com
-
jasonunrein@kscable.com
-
muskrat@texas.net