manoser has asked for the wisdom of the Perl Monks concerning the following question:

I want to gain access to a shared folder from a server I can not access physically. So my perl script, which will run on that server, has to do it for me.

In order to skip the netresource module, I wanted to use the shell command "net use" to establish the connection.

That is where the trouble emerged.

Perl returns the warning "Can't spawn cmd.exe: No such file or directory". Even if I add "C:/WINNT/system32" to @INC, perl simply surrenders. What do I do wrong?

Thanks in advance for Your adjuvant replies.

2005-03-05 Edited by Arunbear: Changed title from 'system() on windoze', as per Monastery guidelines

Replies are listed 'Best First'.
Re: system() on Win32
by Corion (Patriarch) on Mar 04, 2005 at 07:32 UTC

    @INC is not the variable to look for when you want to change the OS search path. If you're interested in what @INC does, perldoc perlvar will tell you what it is for.

    It is $ENV{PATH} that you are interested in, but I really wonder, since by default, C:\WINNT\system32 is in the search path, because Windows uses $ENV{PATH} to look for DLLs as well. If your script is running under some weird restricted setup, you can either manually add $ENV{WINDIR} to $ENV{PATH}, or even hardcode the windows directory. You can also try to start the net.exe program directly, although I think that Perl will try to start cmd.exe still:

    system('c:\\winnt\\system32\\net.exe','use',"$server\\\\$share") or die "Couldn't launch net.exe: $!";

    You find the documentation for system by typing perldoc -f system at the command prompt, or by visiting system.

    The alternative way of manually setting up the search path would work like this:

    my $mypath = 'C:\\Winnt\\system32'; $ENV{PATH} .= ';' . $mypath;
Re: system() on Win32
by maa (Pilgrim) on Mar 04, 2005 at 07:46 UTC

    Hi, manoser

    what OS is it?

    If you're on XP then the account may be restricted by GPO (Group Policy Objects) rather than NTFS permissions. Have you tried logging on as that account and doing START/Run "cmd.exe" to see what happens?

    HTH
    -- Mark

Re: system() on Win32
by ZlR (Chaplain) on Mar 04, 2005 at 08:59 UTC
    To manage network drives you don't really need to use a system call : you can use Win32::NetRessource (activestate default install) .

    zlr

Re: system() on Win32
by PodMaster (Abbot) on Mar 04, 2005 at 07:31 UTC
    @INC is for modules, not programs.
    C:\>perl -e"system qw[ net stat ]" The syntax of this command is: NET [ ACCOUNTS | COMPUTER | CONFIG | CONTINUE | FILE | GROUP | HELP | HELPMSG | LOCALGROUP | NAME | PAUSE | PRINT | SEND | SESSION | SHARE | START | STATISTICS | STOP | TIME | USE | USER | VIEW ]
    If you want to spawn cmd.exe, you should specify the absolute path to cmd.exe.

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

      On every sane windows system cmd.exe is in the PATH and therefore specifying the complete path is unnecessary.

      I strongly believe it is a security policy issue as mentioned elsewhere in this thread.


      holli, /regexed monk/
      Honestly, I do not know how to specify the absolute path to cmd.exe.

      I mean, You can't just pass it as an additional variable when You call system, can You?

      Thanks