简体   繁体   中英

calling cmd from python windows error 2

I am tring to call the cmd command "move" from python.

  cmd1 = ["move", spath , npath]
  startupinfo = subprocess.STARTUPINFO()
  startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
  p = subprocess.Popen(cmd1, startupinfo=startupinfo)

While the comammand works in the cmd. I can move files. With this python code i get:

WindowsError: [Error 2] The system cannot find the file specified

Spath and npath, are absolute paths to folders, so being in another directory should not matter.

[edit] Responding to Tim's answear: The how do i move a folder?

move is built-in into the cmd shell, so it's not a file command that you can call this way.

You could use shutil.move() , but this "forgets" all alternate data stream, ACLs etc.

尝试使用cmd1 = ["cmd", "/c", "move", spath, npath]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM