# redirect stderr into stdout
$p = &{python -V} 2>&1
# check if an ErrorRecord was returned
$version = if($p -is [System.Management.Automation.ErrorRecord])
{
# grab the version string from the error message
$p.Exception.Message
}
else
{
# otherwise return as is
$p
}
似乎}。在
python -V
将版本字符串输出到stderr
,而不是{您可以使用流重定向器将错误重定向到标准输出:
如果您确定系统上的所有python版本都会这样做,可以将其缩减为:
^{pr2}$相关问题 更多 >
编程相关推荐