Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从批处理脚本使用powershell_Powershell_Batch File_Windows 10 - Fatal编程技术网

从批处理脚本使用powershell

从批处理脚本使用powershell,powershell,batch-file,windows-10,Powershell,Batch File,Windows 10,我想利用powershell在批处理脚本中进行一些简单的数学计算。我能够在批处理脚本中使用 set numerator=3.5 for /f %%i in ('powershell 10/%numerator%') do (set result=%%i) 它正确地将结果变量设置为2.85714285714286,但我无法从批处理脚本调用powershell命令,如powershell[math]::max(3,4),该命令最多返回两个数字。召唤 for /f %%i in ('powershe

我想利用
powershell
在批处理脚本中进行一些简单的数学计算。我能够在批处理脚本中使用

set numerator=3.5
for /f %%i in ('powershell 10/%numerator%') do (set result=%%i)
它正确地将
结果
变量设置为
2.85714285714286
,但我无法从批处理脚本调用powershell命令,如
powershell[math]::max(3,4)
,该命令最多返回两个数字。召唤

for /f %%i in ('powershell [math]::max^(3,4^)') do (set result=%%i)
从批处理脚本将
结果
变量设置为
+


提前感谢您的帮助。

也需要转义。否则,将出现powershell错误

第1行字符:14
+[数学]::max(34)
+~
方法调用中缺少“)”。
第1行字符:15
+[数学]::max(34)
+~
表达式或语句中出现意外标记“4”。
第1行字符:16
+[数学]::max(34)
+~
表达式或语句中的意外标记“)。
+CategoryInfo:ParserError:(:)[],ParentContainerRorRecordEx 异常情况
+FullyQualifiedErrorId:MissingendBranchisinMethodCall

由于字符串在默认情况下在
for/f
循环中标记,因此结果是
+

总之,只需转义逗号即可

for/f%%i in('powershell[math]::max^(3^,4^)do(set result=%i)