繁体   English   中英

Powershell怎么开

[英]How to open Powershell

我想用 VBA(Excel) 启动这个 powershell 命令:
(它在 *.bat 文件中工作。)

copy /b "C:\Users\chris\Desktop\Downloader\2\2.107.ts" + "C:\Users\chris\Desktop\Downloader\2\2.108.ts" ""C:\Users\chris\Desktop\Downloader\2\0001.ts""


我的 Vba 代码:

Dim strCommand
Dim Wsshell    
strCommand = "Powershell.exe -NoExit copy \b ""C:\Users\chris\Downloads\1.ts"" + ""C:\Users\chris\Downloads\2.ts"" + ""C:\Users\chris\Downloads\3.ts"" -Destination ""C:\Users\chris\Downloads\yeah.ts"""
Set Wsshell = CreateObject("WScript.Shell")
Wsshell.Run (strCommand)


Powershell 中的错误:

Copy-Item : Es wurde kein Positionsparameter gefunden, der das Argument "+" akzeptiert.
In Zeile:1 Zeichen:1
+ copy \b C:\Users\chris\Downloads\1.ts + C:\Users\chris\Downloads\2.ts ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Copy-Item], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.CopyItemCommand

这真的不是一个开放的 powershell 问题。

您面临的问题是 cmd 副本与 powershell 副本不同。 在 powershell 中,复制是复制项的别名,而 powershell 不像 cmd 那样使用“+”,它实际上会使用逗号来复制多个文件

请参阅复制项文档

更重要的是,您的实际问题不是复制,但似乎您将 /b 用于一个目的地,因此您正在执行二进制合并。

我建议在 powershell 中这样做

get-content "C:\Users\chris\Downloads\1.ts", "C:\Users\chris\Downloads\2.ts", "C:\Users\chris\Downloads\3.ts" -Encoding Byte -Read 512 | Set-Content "C:\Users\chris\Downloads\yeah.ts" -Encoding Byte

只需确保在从 VB 调用时避开“引号”

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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