* getlogin : no such file or directory ??
@ 2007-04-12 8:50 Pietro Abate
2007-04-12 12:06 ` [Caml-list] " Brian E. Aydemir
0 siblings, 1 reply; 2+ messages in thread
From: Pietro Abate @ 2007-04-12 8:50 UTC (permalink / raw)
To: ocaml ml
Hi all,
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 ?
:)
p
--
++ Blog: http://blog.rsise.anu.edu.au/?q=pietro
++
++ "All great truths begin as blasphemies." -George Bernard Shaw
++ Please avoid sending me Word or PowerPoint attachments.
See http://www.fsf.org/philosophy/no-word-attachments.html
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Caml-list] getlogin : no such file or directory ??
2007-04-12 8:50 getlogin : no such file or directory ?? Pietro Abate
@ 2007-04-12 12:06 ` Brian E. Aydemir
0 siblings, 0 replies; 2+ messages in thread
From: Brian E. Aydemir @ 2007-04-12 12:06 UTC (permalink / raw)
To: Pietro Abate; +Cc: ocaml ml
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-04-12 12:06 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-04-12 8:50 getlogin : no such file or directory ?? Pietro Abate
2007-04-12 12:06 ` [Caml-list] " Brian E. Aydemir
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox