首页 > 解决方案 > 'copy-item' 未被识别为内部或外部命令

问题描述

我有这个问题:

'copy-item' 未被识别为内部或外部命令

我该如何解决?

system ("start powershell  get-Childitem -Path 'D:\Program Files\12' -recurse -filter *.dxf | copy-item -Destination 'C:\22'")

标签: powershellcmd

解决方案


问题是因为您将整个字符串"start powershell get-Childitem -Path 'D:\Program Files\12' -recurse -filter *.dxf | copy-item -Destination 'C:\22'作为单个命令运行。

它的作用是start powershell get-Childitem -Path 'D:\Program Files\12' -recurse -filter *.dxf先运行命令,然后copy-item -Destination 'C:\22'在命令运行后运行。现在copy-item显然在 CMD 中不存在,因此它会引发错误。

您需要将字符串get-Childitem -Path 'D:\Program Files\12' -recurse -filter *.dxf | copy-item -Destination 'C:\22'括在引号中,以便将整个字符串提供给 powershell 运行。

作为一个简单的示例,该命令start powershell Get-ChildItem | write-output失败,但该命令start powershell "Get-ChildItem | write-output"按预期工作。


推荐阅读