2014-02-22 2 views
1

실행중인 응용 프로그램에 pywin32를 사용하고 있습니다. 문제는 성공적으로 실행하려면 응용 프로그램 exe 파일의 루트 디렉토리에 있어야합니다. 예를 들어 우리가 응용 프로그램 루트에 메모장 ++ .exe를 실행하려고합니다. CMD에서 나는이 시도하고 일 : shell.Run와 파이썬에서 실행하는 경우Python pywin32 디렉토리에서 응용 프로그램을 실행 중입니다.

C:\>(cd "C:\Program Files (x86)\Notepad++" && notepad++.exe) 

을하지만 :

import win32com.client 
shell = win32com.client.Dispatch("WScript.Shell") 
shell.Run('(cd "C:\Program Files (x86)\Notepad++" && notepad++.exe)') 

반환 예외 :

Traceback (most recent call last): 
File "<stdin>", line 1, in <module> 
File "<COMObject WScript.Shell>", line 2, in Run 
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024894), None) 

를 디코딩 할 때 :

import win32api 
e_msg = win32api.FormatMessage(-2147024894) 

이상한 말 : 더 간단하게,

shell.Run('cmd /K (cd "C:\Program Files (x86)\Notepad++" && notepad++.exe)') 

또는 :

'The system cannot find the file specified.\r\n' 

답변

1

그것은 나를 위해 작동

shell.Run('cmd /K cd "C:\Program Files (x86)\Notepad++" && notepad++.exe') 
관련 문제