powershell - PowerShell 中的调用表达式无法识别运算符
问题描述
我正在尝试在 PowerShell 脚本中运行docker命令并测试该命令是否不成功,但我没有这样做。我在用:
if (!Invoke-Expression -Command docker ps -q -f name=php72) {
#some other code here
}
运行后我得到的错误是:
Line |
31 | if (!Invoke-Expression -Command docker ps -q -f name=php72) {
| ~~~~~~~~~~~~~~~~~~
| The term '!Invoke-Expression' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a
| path was included, verify that the path is correct and try again.
我也尝试过-not
运营商无济于事。
解决方案
添加另一个括号:
if (!(Invoke-Expression -Command docker ps -q -f name=php72)){
#some other code here
}
除非这里!Invoke-Expression
被评估,这是无效的。
最好的方法是这样使用:
docker ps -q -f name=php72 >$null 2>&1
if($lastExitCode -eq 1){"FAILED!"}
推荐阅读
- c - 如何在C中读取通过stdin传递的文件
- scala - Spark:从spark sql查询中提取表列表
- android - 下载文件 arm64-v8a Skobbler
- ios - React Native中的Dimension.get('window').width根据SplashScreen方向而不是当前方向?
- javascript - 使用节点 sqlite3 异步获取所有数据
- python - Django i18n 提供不完整的翻译
- javascript - Javascript:提取字符串中搜索词之后的内容
- security - 唯一哈希作为端点的授权
- javascript - 隐藏div中的php src值更改
- unit-testing - 在 Foq 中模拟具有虚拟内部可设置属性的抽象类