难以将命令行参数传递给robocopy

时间:2017-02-24 23:51:00

标签: python html subprocess batch-processing

我是Python的新手,但很想用它来编写批处理过程。尝试执行下面的代码,除了排除目录选项外,一切正常。有谁知道我可以解决这个问题吗?

import subprocess
subprocess.call(["robocopy",r"c:\rob",r"c:\rob1", "/nocopy", r'/xd gp'])


-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows
-------------------------------------------------------------------------------

  Started : Friday, February 24, 2017 6:47:37 PM
   Source - c:\fred\
     Dest - c:\fred1\

    Files :
  Options : /NOCOPY /R:1000000 /W:30

------------------------------------------------------------------------------

ERROR : Invalid Parameter #4 : "/xd gp"

       Simple Usage :: ROBOCOPY source destination /MIR

             source :: Source Directory (drive:\path or \\server\share\path).
        destination :: Destination Dir  (drive:\path or \\server\share\path).
               /MIR :: Mirror a complete directory tree.

    For more usage information run ROBOCOPY /?



****  /MIR can DELETE files as well as copy them !

1 个答案:

答案 0 :(得分:1)

我想你想要:

import subprocess
subprocess.call(["robocopy",r"c:\rob",r"c:\rob1", "/nocopy", r'/xd', 'gp'])

将选项的值与选项的值分开,因为它们应该是robocopy的单独参数,但是它们将它们作为单个参数

  

'/ xd gp'