[英]How to pass an array to the arguments in Start-Process in Powershell?
I am writing a script to play certain files in a player.我正在编写一个脚本来播放播放器中的某些文件。 I use Get-ChildItem to get an array of file names.
我使用 Get-ChildItem 来获取文件名数组。 Then I want to use Start-Process to play these files.
然后我想用 Start-Process 来播放这些文件。 However, how can I add these file names to the arguments of the player program?
但是,如何将这些文件名添加到播放器程序的 arguments 中?
I used Start-Process -FilePath "C:\Program Files\DAUM\PotPlayer\PotPlayerMini64.exe" -ArgumentList $selected_items
but it seems it doesn't work and the files are not played.我使用
Start-Process -FilePath "C:\Program Files\DAUM\PotPlayer\PotPlayerMini64.exe" -ArgumentList $selected_items
但它似乎不起作用并且文件没有播放。
Notice there are spaces in the file names.注意文件名中有空格。
Judging by the available command-line options , the following may work (I cannot personally verify):从 可用的命令行选项来看,以下可能有效(我无法亲自验证):
/clipboard
:Appends content(s) from clipboard into playlist and starts playback immediately./clipboard
:将剪贴板中的内容附加到播放列表中并立即开始播放。
# Copy the full names of the files of interest to the clipboard.
Set-Clipboard -Value $selected_items.FullName
# Launch the player and tell it to start playback of the files on the clipboard.
# Parameters -FilePath and -ArgumentList are positionally implied.
Start-Process 'C:\Program Files\DAUM\PotPlayer\PotPlayerMini64.exe' /clipboard
There are file-arguments-based options such as /new
, /insert
, and /add
, but it's unclear to me whether they automatically start playback (may depend on the application's configuration).有基于文件参数的选项,例如
/new
、 /insert
和/add
,但我不清楚它们是否会自动开始播放(可能取决于应用程序的配置)。
You can ForEach-Object :您可以ForEach-Object :
Get-ChildItem . | ForEach-Object {Start-Process -FilePath "C:\Program Files\DAUM\PotPlayer\PotPlayerMini64.exe" -ArgumentList $_.FullName}
You don't need start-process.您不需要启动过程。
& "C:\Program Files\DAUM\PotPlayer\PotPlayerMini64.exe"
C:\Program` Files\DAUM\PotPlayer\PotPlayerMini64.exe
$env:path += ';C:\Program Files\DAUM\PotPlayer'; PotPlayerMini64
I can't test this myself, but it looks like switch /content
can take an array of file paths joined by space characters.我自己无法对此进行测试,但看起来 switch
/content
可以采用由空格字符连接的文件路径数组。
$selected_items = Get-ChildItem -Path 'X:\pathtothefiles' -File | ForEach-Object {
# quote the file paths
'"{0}"' -f $_.FullName
}
$player = "C:\Program Files\DAUM\PotPlayer\PotPlayerMini64.exe"
Start-Process -FilePath $player /content ($selected_items -join ' ')
# or
# & $player /content ($selected_items -join ' ')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.