简体   繁体   English

如何在 Powershell 的 Start-Process 中将数组传递给 arguments?

[英]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.

相关问题 如何通过启动进程 powershell 传递 python 参数 - How to pass python arguments via start-process powershell 在Powershell中,如何将数组作为参数传递,该数组是Start-Process -ArgumentList的多个参数之一 - In Powershell how can I pass an array as an argument, which is one of multiple arguments to Start-Process -ArgumentList 如何通过Powershell启动过程将带引号的参数传递给提升的批处理脚本 - How to pass quoted arguments to elevated batch script via powershell Start-Process 如何将“y”传递给使用 PowerShell Start-Process 启动的 pscp 进程? - How to pass "y" to pscp process started with PowerShell Start-Process? 如何将 If 语句传递给 PowerShell 的启动进程的参数列表? - How to pass an If statement to the Argumentlist of Start-process for PowerShell? 如何在PowerShell中将文字路径传递给Start-process? - How do I pass literal path to Start-process in PowerShell? 将 Arguments 传递给带空格的 Start-Process - Pass Arguments to Start-Process with spaces PowerShell启动过程 - PowerShell Start-Process Powershell:Start-Process 不会将参数传递给 cmd.exe - Powershell: Start-Process doesn't pass arguments to cmd.exe Powershell启动过程,用于启动Powershell会话并传递局部变量 - Powershell Start-Process to start Powershell session and pass local variables
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM