[Israel.pm] directory changes and embedded perl interpreter on windows

Gaal Yahas gaal at forum2.org
Thu Sep 2 12:55:16 PDT 2004

On Thu, Sep 02, 2004 at 10:24:48PM +0300, Moshe Kaminsky wrote:
> I tried to report it as a vim bug, but the author of vim claims that 
> determining the current working directory is left entirely to the perl 
> interpreter. Therefore, it should be a general problem when embedding 
> perl on windows.
> Can someone verify it? Is this a known issue? Is there a workaround?

I can't verify this (I'm not near a Win32 system) but if anyone feels
like it, this should test the hypothesis that this is a bug in embedded
perl on Windows (on unix this works correctly). You may have to modify
my includes; I can't write correct Windows C code off the top of my head.

On unix, you do this to compile and run it:

     [roo at sike:~/src 13] > gcc -o perlcd perlcd.c `perl -MExtUtils::Embed -e ccopts -e ldopts`
     [roo at sike:~/src 14] > ./perlcd ..
     Changing to '..'.
     Perl thinks the current path is '/home/roo'.
     [roo at sike:~/src 15] > 

#include <EXTERN.h>
#include <perl.h>

#ifdef WIN32
#include <direct.h>
#include <unistd.h>

static PerlInterpreter *my_perl;

main (int argc, char **argv, char **env)
    STRLEN n_a;
    char *embedding[] = { "", "-e", "0" };

    my_perl = perl_alloc();
    perl_construct( my_perl );

    perl_parse(my_perl, NULL, 3, embedding, NULL);
    PL_exit_flags -= PERL_EXIT_DESTRUCT_END;

    if (argc > 1) {
        printf("Changing to '%s'.\n", argv[1]);
#ifdef WIN32
    } else {
        printf("Run me with a path (e.g., '..') to see if embedded perl "
                "notices directory changes\n");

    eval_pv("use Cwd; $a = cwd;", TRUE);
    printf("Perl thinks the current path is '%s'.\n", SvPV(get_sv("a", FALSE), n_a));   

Gaal Yahas <gaal at forum2.org>

More information about the Perl mailing list