1

我在 Windows 上。在 CMDER 下,我可以ssh从 Python 调用命令,因为 CMDER 支持它:

(python2) λ python                                                                                                   
Python 2.7.13 |Continuum Analytics, Inc.| (default, May 11 2017, 13:17:26) [MSC v.1500 64 bit (AMD64)] on win32      
Type "help", "copyright", "credits" or "license" for more information.                                               
Anaconda is brought to you by Continuum Analytics.                                                                   
Please check out: http://continuum.io/thanks and https://anaconda.org                                                
>>> import subprocess                                                                                                
>>> subprocess.call('ssh')                                                                                           
usage: ssh [-1246AaCfGgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]                                           
           [-D [bind_address:]port] [-E log_file] [-e escape_char]                                                   
           [-F configfile] [-I pkcs11] [-i identity_file]                                                            
           [-J [user@]host[:port]] [-L address] [-l login_name] [-m mac_spec]                                        
           [-O ctl_cmd] [-o option] [-p port] [-Q query_option] [-R address]                                         
           [-S ctl_path] [-W host:port] [-w local_tun[:remote_tun]]                                                  
           [user@]hostname [command]                                                                                 
255    

不幸的是,我不能从Python控制台做同样的事情

import subprocess
subrocess.call('ssh')
Traceback (most recent call last):
  File "<input>", line 1, in <module>
NameError: name 'subrocess' is not defined
subprocess.call('ssh')
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Anaconda3\envs\python2\lib\subprocess.py", line 168, in call
    return Popen(*popenargs, **kwargs).wait()
  File "C:\Anaconda3\envs\python2\lib\subprocess.py", line 390, in __init__
    errread, errwrite)
  File "C:\Anaconda3\envs\python2\lib\subprocess.py", line 640, in _execute_child
    startupinfo)
WindowsError: [Error 2] The system cannot find the file specified

如何在 IntelliJ 中的 Python 调试器下使用 CMDER 功能?

4

1 回答 1

0

您需要将 ssh 可执行文件添加到路径中,例如在运行时:

import os

os.environ['PATH'] += r';C:\Users\<USER>\Desktop\cmder\vendor\git-for-windows\usr\bin'
subprocess.call('ssh')
于 2018-04-03T09:18:39.883 回答