mik*_*ana 11 ssh powershell cmd openssh
我一直在Windows上玩OpenSSH,看起来缺少正常的Unix别名.当我通过SSH登录到Windows机器时,我不确定它是启动PowerShell还是cmd.在Windows上查看当前运行的shell的正确方法是什么?
not*_*bit 11
我想扩展 @sodawillow 的答案,以区分使用称为 的Powershell ( powershell.exeDesktop )和称为 的PWSH ( pwsh.exeCore ) 。
(dir 2>&1 *`|echo CMD);&<# rem #>echo ($PSVersionTable).PSEdition
# Returns one of: CMD, Core, Desktop
Run Code Online (Sandbox Code Playgroud)
这适用于未实例化子 shell 的所有情况。这意味着它无法通过在 Python 中打开默认子进程来工作,因为它在与窗口交互时始终使用CMD。这实际上是由 Windows 环境变量设置的:ComSpec始终指向C:\Windows\system32\cmd.exe.
例如:
(从 pwsh shell 启动 python 解释器。)
(dir 2>&1 *`|echo CMD);&<# rem #>echo ($PSVersionTable).PSEdition
# Returns one of: CMD, Core, Desktop
Run Code Online (Sandbox Code Playgroud)
对于其他Python shell检测方案,请参阅这篇好文章。
更新:2020-05-01
我设法使上述工作正常进行,但在执行之前始终加载 powershell配置文件会产生令人讨厌的副作用。诀窍是execute=<path-to-powershell-exe>这样指定:
(启动 python CLI。)
>>> import os, subprocess
>>> c="(dir 2>&1 *`|echo CMD);&<# rem #>echo($PSVersionTable).PSEdition"
>>> subprocess.call(c,shell=True)
CMD
Run Code Online (Sandbox Code Playgroud)
我无法规避 powershell 配置文件问题。但显然这是正在研究中的事情。请参阅此处和此处。
所有功劳都归功于PetSerAl,这必须作为一个aswer发布:
(dir 2>&1 *`|echo CMD);&<# rem #>echo PowerShell
Run Code Online (Sandbox Code Playgroud)
在Win32-OpenSSH此命令中也可以工作和输出CMD.
NB:Win32-OpenSSH似乎有点受限,cd在我的系统上无法识别.
| 归档时间: |
|
| 查看次数: |
1249 次 |
| 最近记录: |