I used this script to login SAP session:
from subprocess import call
import win32com.client
import time
import os
GUIPath = 'C:/Program Files (x86)/SAP/FrontEnd/SAPgui/'
WinTitle = 'SAP'
Name = """PRD"""
SID = 'PRD'
InstanceNo = '01'
shell = win32com.client.Dispatch("WScript.Shell")
call(os.path.join(GUIPath, 'SAPgui.exe') + " " + Name + " " + InstanceNo)
however, it always return with the error:
hostname 'PRD' unknown
check you application server name
anyone knows how to fix this? thanks
The variable Name needs to be "PRD"
(the string itself must contain double quotes). Python considers Name = """PRD"""
the same as Name = "PRD"
so it's incorrect because the variable Name will just contain PRD
(missing double quotes).
Hence, need to use string backslash (Name = "\"PRD\""
or other possibilities mentioned here) to maintain the double quote in the variable Name.
Complete code:
from subprocess import call
import win32com.client
import time
import os
GUIPath = 'C:/Program Files (x86)/SAP/FrontEnd/SAPgui/'
WinTitle = 'SAP'
Name = "\"PRD\""
SID = 'PRD'
InstanceNo = '01'
shell = win32com.client.Dispatch("WScript.Shell")
call(os.path.join(GUIPath, 'SAPgui.exe') + " " + Name + " " + InstanceNo)
Thanks for feedback. About
sapgui.exe
, I thought that it'd accept only a host name or IP address as first argument, but it also accepts a logon entry description if it's between double quotes. I tried this PowerShell and it worked:&"C:\Program Files (x86)\SAP\FrontEnd\SAPgui\sapgui.exe" '"Dev system"'
. It took the logon entryDev system
that I had defined in my SAP Logon application. It must be the exact description of the logon entry (and not the system ID). It's case sensitive. SAP didn't describe this feature in Note 103019.By the way, you have passed a logon entry (because it's between double quotes) as first argument of sapgui.exe, so passing the instance number (your second argument) is ignored, as I have shown in my previous comment.
yes, correct. Any instance will be accepted. btw, I tried with the IP address of "message server", but it didn't work. Are you using the same IP address of "message server" or what? Can you show your full script to access SAP with PowerShell through IP address?
Please ask another question (short answer: No, of the dispatcher (dp). If you want to use the message server (ms), few possibilities from note 103019:
/R/<SID>/G/<logon group>
(e.g. "/R/ERP/G/PUBLIC"),/M/<message server>/S/<message server port>/G/<logon group>
(e.g. "/M/server.domain/S/1080/G/PUBLIC"),/R/<SID>/M/<message server>/G/<logon group>
(e.g. "/R/ERP/M/server.domain/G/PUBLIC"), etc.)