Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Issue with backticks in ActiveState

by freddo411 (Chaplain)
on Sep 08, 2009 at 19:33 UTC ( #794207=perlquestion: print w/replies, xml ) Need Help??

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

I'm not understanding how the backticks operator is working in ActiveState. How can I execute $cmd so that it "works" as I intend?
foreach ( 7100 .. 7114 ) { my $path = File::Spec->catdir( $topdir, "$_/hosted/docs/cdm4/msoff +ice" ); my $cmd = "rmdir /s /q $path"; print "$cmd \n"; print `$cmd` . "\n"; }
Some output shows that it is doing something funny to the /s and /q cmdline options of rmdir.
rmdir /s /q D:\sites\cust\7112\hosted\docs\cdm4\msoffice rmdir: failed to remove `/s': No such file or directory rmdir: failed to remove `/q': No such file or directory rmdir: failed to remove `D:\\sites\\cust\\7112\\hosted\\docs\\cdm4\\ms +office': Directory not empty
I'm running:
D:\z>perl -v <br> This is perl, v5.10.0 built for MSWin32-x86-multi-thread

-------------------------------------
Nothing is too wonderful to be true
-- Michael Faraday

Replies are listed 'Best First'.
Re: Issue with backticks in ActiveState
by GrandFather (Saint) on Sep 08, 2009 at 21:10 UTC

    What OS are you using? Are you sure the OS version of rmdir is being found, and not some rogue application that's pretending to be rmdir? Running

    perl -e "my $cmd = qq(rmdir /s /q TempDirTree); print `$cmd` . qq(\n)"

    from the command line works as expected for me using Vista64 and ActiveState Perl 5.8.7.


    True laziness is hard work
Re: Issue with backticks in ActiveState
by pKai (Priest) on Sep 08, 2009 at 21:15 UTC

    You probably have a rmdir.exe somewhere in your PATH.
    Check to verify: where rmdir.exe.

    The rmdir, probably from the unxutils will not accept options with slashes, contrary to the cmd built-in rmdir.

    A perl -e "`rmdir /s /q testdir`;" works flawless for me (no exe present here).

      You probably have a rmdir.exe somewhere in your PATH.
      Bingo. Thanks for pointing this out.

      -------------------------------------
      Nothing is too wonderful to be true
      -- Michael Faraday

Re: Issue with backticks in ActiveState
by toolic (Bishop) on Sep 08, 2009 at 20:21 UTC
    print `$cmd` . "\n";
    That seems like a strange use of backticks. Backticks are used to collect output from a command, and you are just passing the output to print. Have you tried using system?
    system $cmd;
Re: Issue with backticks in ActiveState
by ikegami (Pope) on Sep 09, 2009 at 00:08 UTC
    File::Path's rmtree will do the trick much more cleanly.
Re: Issue with backticks in ActiveState
by Marshall (Canon) on Sep 08, 2009 at 21:38 UTC
Re: Issue with backticks in ActiveState
by Anonymous Monk on Sep 08, 2009 at 21:24 UTC
    perl -V:sh sh='cmd /x /c';
    D:\>perl -le"print `rmdir /?`" rmdir: `/2': Invalid argument D:\>perl -le"print `rmdir --help`" Usage: rmdir [OPTION]... DIRECTORY... Remove the DIRECTORY(ies), if they are empty. --ignore-fail-on-non-empty ignore each failure that is solely because a directo +ry is non-empty -p, --parents remove DIRECTORY, then try to remove each directory component of that path name. E.g., `rmdir -p a/b/c' + is similar to `rmdir a/b/c a/b a'. -v, --verbose output a diagnostic for every directory processed --help display this help and exit --version output version information and exit Report bugs to <bug-coreutils@gnu.org>. D:\>perl -le"print `cmd /x /c rmdir /?`" Removes (deletes) a directory. RMDIR [/S] [/Q] [drive:]path RD [/S] [/Q] [drive:]path /S Removes all directories and files in the specified directo +ry in addition to the directory itself. Used to remove a dir +ectory tree. /Q Quiet mode, do not ask if ok to remove a directory tree wi +th /S
    perl -MExtUtils::Command -e rm_rf -- D:\sites\cust\7112\hosted\docs/cdm4\msoffice

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://794207]
Approved by AnomalousMonk
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2021-04-18 11:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?