电源外壳通过参数
问题描述:
我将$ nextday和$ currrentyear传递给在我的powershell脚本中执行的.exe。似乎这些论点没有通过,为什么?电源外壳通过参数
$nextday = (Get-Date).AddDays(-1).ToString("M/dd/yyyy")
$currentgetyear = (Get-Date).ToString("yyyy")
& "C:\tmt.exe" YEAR= $currentgetyear DATE= $nextday
答
为什么在词语之间使用空格?看看它是如何通过软件解析的:
[21:50:46] > & echoargs YEAR= $currentgetyear DATE= $nextday
Arg 0 is <YEAR=>
Arg 1 is <2013>
Arg 2 is <DATE=>
Arg 3 is <2.26.2013>
然而,这是解析我应该怎么猜。
[21:50:58] > & echoargs YEAR=$currentgetyear DATE=$nextday
Arg 0 is <YEAR=2013>
Arg 1 is <DATE=2.26.2013>
所以我的解决办法:删除空格,如:
& "C:\tmt.exe" YEAR=$currentgetyear DATE=$nextday
答
尝试
& "C:\tmt.exe" ("YEAR={0}" -f (get-date).Year) ("DATE={0:M/dd/yyyy}" -f (get-date).AddDays(-1))
比尔