powershell - 'copy-item' 未被识别为内部或外部命令
问题描述
我有这个问题:
'copy-item' 未被识别为内部或外部命令
我该如何解决?
system ("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'
作为单个命令运行。
它的作用是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"
按预期工作。