[英]Powershell variable for cmd argument
我想為一個cmd參數使用一個powershell變量,但我不知道如何制作它。
function iptc($file)
{
$newcredit = correspondance($credit)
$cmd = '& C:\exiftool\exiftool.exe -S -t -overwrite_original -Credit=$newcredit $file.FullName'
Invoke-Expression $cmd
}
例如,newcredit可以是“James”,但在我的情況下,當我運行命令時-Credit將只是“$ newcredit”。
問候
單引號('')不會擴展字符串中的變量值。 您可以使用雙引號(“”)來解決此問題:
$cmd = "& C:\exiftool\exiftool.exe -S -t -overwrite_original -Credit=$newcredit $file.FullName"
或者,通過我最經常使用的方法,使用字符串格式:
$cmd = '& C:\exiftool\exiftool.exe -S -t -overwrite_original -Credit={0} {1}' -f $newcredit, $file.FullName
如果其中任何一個參數中有一個空格,那么參數將需要在輸出中用雙引號括起來。 在那種情況下,我肯定會使用字符串格式:
$cmd = '& C:\exiftool\exiftool.exe -S -t -overwrite_original -Credit="{0}" "{1}"' -f $newcredit, $file.FullName
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.