在 Powershell 中,我可以运行以下命令
.\exiftool.exe '-GPSLatitude*=56.9359839838' '-GPSLongitude*=-4.4651045874' DSC01008.JPG '-overwrite_original_in_place'
这工作得很好,并且需要在这些参数周围放置单引号。我经历了不同位置的各种迭代,上面是我让它工作的唯一方法。
我的问题是 ->我试图用编程值替换这些值。就像下面这样。
$lat = 56.9359839838
$lon = -4.4651045874
$fileName = 'DSC01008.JPG'
.\exiftool.exe -GPSLatitude*=$lat -GPSLongitude*=$lon $fileName '-overwrite_original_in_place'
我已经用单引号/反引号/双引号进行了多次尝试,尝试连接以及我能想到的任何其他东西 - 但这种神奇的格式还没有出现!
关于我做错了什么的任何想法?
举个例子,我认为这确实有效,但事实并非如此。但它与硬编码时执行的命令相匹配。
编辑/更新 - 命令内需要 *,否则不起作用。它们用于绕过不传入引用定位器。如果您要在 PS 中运行这些命令,那么这些就是您得到的错误。
cmd -> .\exiftool.exe "-GPSLatitude*=$lat" "-GPSLongtitude*=$lon" $FileName
错误->
No Error, but the file does not get any GPS tags. Nothing actually modified.
cmd ->
$combLat = "`'-GPSLatitude*=$lat`'" # + "
$combLon = "`'-GPSLongitude*=$lon`'" # + "'"
$combined = "$combLat $combLon $fileName"
# $combined will output the following: '-GPSLatitude*=-3.4651045874' '-GPSLongitude*=55.9359839838' 'E:\CameraAddGPS\TestFolder\DSC01010.JPG'
.\exiftool.exe $combined
错误->
.\exiftool.exe : Wildcards don't work in the directory specification
At E:\CameraAddGPS\TestFolder\demo.ps1:25 char:1
+ .\exiftool.exe $combined
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Wildcards don't...y specification:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
No matching files
更新 2 - 这会起作用,但我不想更新图像两次。
$combLat = '-GPSLatitude*=' + $lat
$combLon = '-GPSLongitude*=' + $lon
.\exiftool.exe $combLat $fileName '-overwrite_original_in_place'
.\exiftool.exe $combLon $fileName '-overwrite_original_in_place'
问题是,纬度和经度变元的“联接”直接向-GPSLatitute*
和-GPSLongtitude*
后参数名称=
标志。(-
初始字符阻止 PowerShell 调用变量扩展 - 请参阅GitHub 问题 #14587。)
解决此问题的一种方法是将-GPSLatitude*
和-GPSLongtitude*
参数"
括在引号中;例如
.\exiftool.exe "-GPSLatitude*=$lat" "-GPSLongtitude*=$lon" $FileName -overwrite_original_in_place
另一种方法是在-
字符前加上反引号 ( `
); 例如:
.\exiftool.exe `-GPSLatitude*=$lat `-GPSLongitude*=$lon $fileName -overwrite_original_in_place
我更喜欢第一个变体,因为它对我来说更具可读性。
除了#1:'
最后一个参数周围不需要单引号。他们没有伤害,但他们也没有做任何事情。
旁白 #2:如果您在命令前加上getargs
可用的命令前缀,您可以看到 PowerShell 正在运行的实际命令行:
https://github.com/Bill-Stewart/getargs/releases
该getargs
实用程序输出实际命令行而不进行任何解析或解释,并将显示 PowerShell 将运行的实际命令。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句