0

I have a Python program that copies files using

os.system("cp -rf %s/bs %s" % (codeHome,destPath))

It's fine in Linux, but when trying to run in Windows (PowerShell) I'm getting the message

'cp' is not recognized as an internal or external command,
operable program or batch file.

What should I be doing instead?

interstar
  • 26,048
  • 36
  • 112
  • 180
  • 2
    Why not use the builtin python libraries? – Padraic Cunningham May 25 '16 at 00:10
  • There is a similar thread on stack overflow [This gets rid of using the cp function](http://stackoverflow.com/questions/123198/how-do-i-copy-a-file-in-python) – Altronicx May 25 '16 at 00:10
  • `os.system` uses cmd.exe, not PowerShell. The python.exe process is not running *in* PowerShell. You probably mean it's *attached* to a console for its standard I/O handles, where the console is conhost.exe (or csrss.exe prior to Win 7) and the parent process is powershell.exe, which happens to be attached to the same console and is waiting for Python to exit. Other than being the parent process, PowerShell has no bearing on the problem. You seem to need a single, cross-platform statement, so `shutil` is probably what you want, but it's very basic on Windows (e.g. doesn't copy security). – Eryk Sun May 25 '16 at 05:22

0 Answers0