【发布时间】:2021-07-11 20:54:33
【问题描述】:
在 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 中运行这些命令,则会出现这些错误。
命令->
.\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'
【问题讨论】:
-
请更新您的minimal reproducible example(图片大多不受欢迎)。
-
您错过了分享最重要的细节,即您收到的错误消息。
-GPSLatitude*是什么意思?我认为您需要指定不带通配符且不带=(等号)的完整选项名称,例如:-GPSLatitude $lat -
更新了它,并附上了一些例子。不过,您将需要 exiftool 来运行示例。命令中肯定需要通配符和 =,否则它们会失败。作为一个方面,如果我将命令分成两部分,那么我可以让它工作。 cmets 中的代码不起作用。将再次更新 Q。
标签: string powershell cmd