[prev in list] [next in list] [prev in thread] [next in thread] 

List:       haskell-cafe
Subject:    Re: [Haskell-cafe] How to get a file path to the program invoked?
From:       Alexey Khudyakov <alexey.skladnoy () gmail ! com>
Date:       2011-12-01 20:30:41
Message-ID: 4ED7E3F1.5090202 () gmail ! com
[Download RAW message or body]

On 01.12.2011 23:47, dokondr wrote:
> To be precise, $0 always contains the path to the program called. You
> are right, this path will change depending on location from which the
> program was called. So $0 is OK for my case, while current directory  is
> unrelated.
>
Actually it contains whatever was passed to exec. By convention this is 
program name but it could be anything

#include <stdio.h>
#include <unistd.h>

int main(int argc, char** argv)
{
     if( argc != 1 ) {
         printf("%i: %s\n", argc, argv[0] );
     } else {
         execl("./argv","Random junk","",0);
     }
     return 0;
}

$ gcc argv.c -o argv && ./argv
2: Random junk



> Try this:
>
> #!/bin/sh
> echo "Arg 0: $0"
> echo "All Parameters:  [$@]"
>
> Again, any way to get the same functionality in GHC?
>
getArgs and getProgName should do the trick

http://hackage.haskell.org/packages/archive/base/latest/doc/html/System-Environment.html

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic