[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2007-04-12 (12:06) |
From: | Brian E. Aydemir <baydemir@c...> |
Subject: | Re: [Caml-list] getlogin : no such file or directory ?? |
On Apr 12, 2007, at 4:50 AM, Pietro Abate wrote: > why the Unix.getlogin function returns "no such file or directory" > if the unix getlogin() function returns null (see getlogin.c) ? > > ex: > ----------- > let main () = > try > print_string (Unix.getlogin()) > with Unix.Unix_error(e,_,_) -> > failwith (Unix.error_message e) > ;; > > main () > --------- > > echo "a" | ./a.out > Fatal error: exception Failure(No such file or directory") > > How can I use getlogin if I want to pass something on the standard > input > to my program ? > > The same example works with MacOsX. Why this difference ? It looks like OCaml simply calls the operating system's implementation of getlogin(). I ran into a similar issue with Python code a while back, so that's where my experience with this comes from. The problem is that it seems not all Unix-like operating systems implement getlogin() in exactly the same way. For example, getlogin () under Linux dies with the "No such file or directory" error when standard-in is not a terminal. getlogin() under Mac OS X doesn't seem to care what standard-in is. The man pages for getlogin might say something about this, as well. My solution was to use getpwuid(getuid()) instead of getlogin(). Cheers, Brian