使用 pywinauto 自动执行 SAP 提取。我发誓这段代码 - 直接从 SWAPY 复制 - 昨天起作用了。
from pywinauto.application import Application
app = Application().Start(cmd_line = u"C:\\'Program Files (x86)'\\SAP\\FrontEnd\\SAPgui\\saplogon.exe")
window = app.Dialog
window.Wait('ready')
edit = window.Edit
edit.ClickInput()
这给了我以下错误:
error: Traceback (most recent call last) ~\AppData\Local\Continuum\Anaconda3\lib\site-packages\pywinauto\application.py in start(self, cmd_line, timeout, retry_interval, create_new_console, wait_for_idle, work_dir) 991 work_dir, # If None - use parent's starting directory. --> 992 start_info) # STARTUPINFO structure. 993 except Exception as exc:
error: (2, 'CreateProcess', 'The system cannot find the file specified.')
During handling of the above exception, another exception occurred:
AppStartError Traceback (most recent call last) in () 1 from pywinauto.application import Application 2 ----> 3 app = Application().Start(cmd_line=u"C:\'Program Files (x86)''\SAP\FrontEnd\SAPgui\saplogon.exe") 4 window = app.Dialog 5 window.Wait('ready')
~\AppData\Local\Continuum\Anaconda3\lib\site-packages\pywinauto\application.py in start(self, cmd_line, timeout, retry_interval, create_new_console, wait_for_idle, work_dir) 995 message = ('Could not create the process "%s"\n' 996 'Error returned by CreateProcess: %s') % (cmd_line, str(exc)) --> 997 raise AppStartError(message) 998 999 self.process = dw_process_id
AppStartError: Could not create the process "C:'Program Files (x86)''\SAP\FrontEnd\SAPgui\saplogon.exe" Error returned by CreateProcess: (2, 'CreateProcess', 'The system cannot find the file specified.')
我正在使用 Python 3.6.4::Anaconda 自定义(64 位)和 pywingui 版本 222 运行 Win7 64 位。我可以将命令剪切并粘贴到 cmd 窗口中,它可以正常启动应用程序。
我更改了引号。我将字符串更改为原始字符串,并删除了单个 \
的 \\
我已经 phlummoxxed。
另外 - 昨天当它“工作”时,单击 SAP GUI 740 版本中的元素是一个真正的挑战。有什么技巧可以克服他们混淆用户界面的方式吗?
最佳答案
将 u"C:\\'Program Files (x86)'\\SAP\\FrontEnd\\SAPgui\\saplogon.exe"
更改为 r'C:\\Program文件 (x86)\\SAP\\FrontEnd\\SAPgui\\saplogon.exe'
解决了问题
关于python - 应用程序启动错误: CreateProcess: The system cannot find the file specified,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49244613/