2013-08-20 5 views
0

이 이맥스 명령 (make-comint-in-buffer "Python" nil "python" nil "-i") 또는 (make-comint-in-buffer "git" nil "C:/Program Files (x86)/Git/bin/sh.exe" nil "--login" "-i")은 이맥스 버퍼에서 프롬프트를 가져 와서 파이썬의/sh.exe의 대화식 터미널을 파이썬 프로세스를 죽이지 않고 어떻게 처리합니까? xxxxx 프로세스를 종료하지 않고 xxxxx.exe 터미널 창을 닫는 방법?

나는 소스가 나는 find 수 없었다 C 컴파일 된 코드를, 인, processpmake-comint-in-buffer의 소스 코드에 얕은 다이빙을 복용하지만, 충돌에 의해 알아 내기 위해 노력했다.

나는이 질문을하고 그 이유는 pythonw 사용하지 않고 this 질문에 다른 대답을 찾을 수 있습니다 (자신의 아닌가요를 예를 들어 mayapy.exemayapyw.exe).

+1

그것은 당신이 앞서-의 시간을 결정해야합니다 콘솔 응용 프로그램 또는 윈도우 응용 프로그램과 같은 프로그램을 실행할지 여부를 윈도우의 기본 제한 사항입니다. 이것이 바로 "pythonw"와 ".pyw"가 첫 번째 장소에 존재하는 이유입니다. 그들은 필요 없기 때문에 다른 OS에는 존재하지 않습니다. 프로그램이 실행을 시작한 후에 그런 종류의 것을 결정할 수 있습니다. 따라서 콘솔 앱을 사용하는 경우 하위 앱을 창 앱으로 실행하거나 새 셸 프로세스 (및 새 창)를 생성해야합니다. –

답변

1

Emacs는 CreateProcess에 SHOWWINDOW 플래그를 사용하여 하위 프로세스와 관련된 콘솔 창의 표시를 제어합니다. create_child in w32proc.c에서

키 코드는 다음과 같습니다

if (NILP (Vw32_start_process_show_window) && !is_gui_app) 
    start.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; 
else 
    start.dwFlags = STARTF_USESTDHANDLES; 

start.wShowWindow = SW_HIDE; 

if (!CreateProcess (exe, cmdline, &sec_attrs, NULL, TRUE, flags, env, dir, &start, &cp->procinfo)) 
{ ... 
} 
0

나는 이맥스 명령이 어떻게 작동 하는지를 짐작할 수 있으므로 실제로 거기에서 당신을 도울 수는 없다 ... 그러나 그러나 나는 창을 숨길 수있는 방법을 제공 할 수있다. CTypes 모듈을 사용하고 Windows-API를 호출하여 Window/Python-prompts ID/Hwin을 얻은 다음 해당 창을 숨기면 가능합니다.

이렇게하면 스크립트에이 코드를 가져 오거나 포함시킨 다음 스크립트에서 함수/함수를 호출해야합니다. 스크립트가 실행되면 프롬프트를 숨겨야합니다. 사용법은 "main.py" -part를 참조하십시오.

Window.py

from ctypes import * 

user32 = windll.user32 

BOOL = c_bool 
INT  = c_int 
LONG = c_long 
LPVOID = c_void_p 
LPTSTR = c_wchar_p 
HWND = LPVOID 
LPARAM = LPVOID 

GW_OWNER = 4 
GWL_EXSTYLE = -20 
WS_EX_TOOLWINDOW = 128 
WS_EX_APPWINDOW = 262144 

#------------------------------------------------------------------------ 

def GetWindowLong(hwnd, index): 
    user32.GetWindowLongW.argtypes = [HWND, INT] 
    return user32.GetWindowLongW(hwnd, index) 

def GetWindow(hWnd, uCmd): 
    user32.GetParent.argtypes = [HWND, INT] 
    return user32.GetWindow(hWnd, uCmd) 

def GetParent(hwnd): 
    user32.GetParent.argtypes = [HWND] 
    return user32.GetParent(hwnd) 

def IsWindowVisible(hwnd): 
    user32.IsWindowVisible.argtypes = [HWND] 
    return user32.IsWindowVisible(hwnd) 

def GetWindowTextLength(hwnd): 
    user32.GetWindowTextLengthW.argtypes = [HWND] 
    return user32.GetWindowTextLengthW(hwnd) 

def GetWindowText(hwnd): 
    length = GetWindowTextLength(hwnd) 
    if not length: return False 
    buff = create_unicode_buffer(length + 1) 
    user32.GetWindowTextW.argtypes = [HWND, LPTSTR, INT] 
    res = user32.GetWindowTextW(hwnd, buff, length + 1) 
    if res: return buff.value 
    else: return False 

def isRealWindow(hwnd): 
    """ Check if a given window is a real Windows application frame.. 
     Returns a BOOL """ 

    if not IsWindowVisible(hwnd): 
     return False 
    if GetParent(hwnd) != 0: 
     return False 
    hasNoOwner = GetWindow(hwnd, GW_OWNER) == 0 
    lExStyle = GetWindowLong(hwnd, GWL_EXSTYLE) 
    if (((lExStyle & WS_EX_TOOLWINDOW) == 0 and hasNoOwner) 
     or ((lExStyle & WS_EX_APPWINDOW != 0) and not hasNoOwner)): 
     if GetWindowText(hwnd): 
      return True 
    return False 

class WindowEnumerator(object): 
    """ Window enumerator class. You can pass it's instances 
     as callback functions in window enumeration APIs. """ 

    def __init__(self): 
     self.hwnd = [] 

    def __call__(self, hwnd, lParam): 
     self.hwnd.append(hwnd) 
     return True 

class __EnumWndProc(WindowEnumerator): 
    pass 

def EnumWindows(): 
    WNDENUMPROC = WINFUNCTYPE(BOOL,HWND,LPARAM) 
    _EnumWindows = user32.EnumWindows 
    _EnumWindows.argtypes = [WNDENUMPROC, LPARAM] 
    _EnumWindows.restype = BOOL 

    EnumFunc = __EnumWndProc() 
    lpEnumFunc = WNDENUMPROC(EnumFunc) 
    if not _EnumWindows(lpEnumFunc, None): 
     errcode = GetLastError() 
     if errcode not in (ERROR_NO_MORE_FILES, ERROR_SUCCESS): 
      raise WinError(errcode) 
    return EnumFunc.hwnd 

def GetWindowByName(title): 
    window = [] 
    hwnds = EnumWindows() 
    for hwnd in hwnds: 
     if not isRealWindow(hwnd): 
      pass 
     else: 
      wndtitle = GetWindowText(hwnd) 
      if title.lower() in wndtitle.lower(): 
       return (hwnd, wndtitle) 
    return False 

def ShowWindow(hWnd, arg=0): 
    user32.ShowWindow.argtypes = [HWND, c_int] 
    return user32.ShowWindow(hWnd, arg) 

main.py

import Window 

# Pass the full or partial title of the window that should be hidden. 
wnd = Window.GetWindowByName('xxxxxxx.exe') 
if wnd: 
    Window.ShowWindow(wnd[0], 0) #Hide it. 0=SW_HIDE, 5 = SW_SHOW. 

나는이 트릭을 수행 바랍니다.