-
-
Save FriedEgg/9085229 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.sas.iom.SASIOMDefs.GenericError; | |
import com.sas.services.connection.ConnectionInterface; | |
import com.sas.services.connection.ZeroConfigWorkspaceServer; | |
import com.sas.services.connection.ManualConnectionFactoryConfiguration; | |
import com.sas.services.connection.ConnectionFactoryManager; | |
import com.sas.services.connection.ConnectionFactoryInterface; | |
import com.sas.services.connection.ConnectionFactoryException; | |
import com.sas.services.connection.SecurityPackageCredential; | |
import com.sas.iom.SAS.ILanguageService; | |
import com.sas.iom.SAS.IWorkspace; | |
import com.sas.iom.SAS.IWorkspaceHelper; | |
public class SASWorkspaceExample { | |
public SASWorkspaceExample() { | |
} | |
public static void main(String[] args) { | |
int slen; | |
String pgm; | |
String lst; | |
String log; | |
IWorkspace wksp; | |
ILanguageService lang; | |
ConnectionInterface cx = null; | |
boolean failed=false; | |
try { | |
ZeroConfigWorkspaceServer server = new ZeroConfigWorkspaceServer(); | |
ManualConnectionFactoryConfiguration config = new ManualConnectionFactoryConfiguration(server); | |
ConnectionFactoryManager manager = new ConnectionFactoryManager(); | |
ConnectionFactoryInterface factory = manager.getFactory(config); | |
SecurityPackageCredential cred = new SecurityPackageCredential(); | |
cx = factory.getConnection(cred); | |
} catch (ConnectionFactoryException e) { | |
System.out.print(e.getMessage()); | |
failed=true; | |
} | |
if (!failed) { | |
wksp = IWorkspaceHelper.narrow(cx.getObject()); | |
lang = wksp.LanguageService(); | |
pgm = "options formchar='|----|+|---+=|-/\\<>*';"; | |
pgm += "ods listing; proc means data=sashelp.cars mean mode min max; run;"; | |
try { | |
lang.Submit(pgm); | |
slen = 1; | |
while (slen > 0) { | |
lst = lang.FlushList(9999999); | |
slen = lst.length(); | |
if (slen > 0) { | |
System.out.print(lst); | |
} | |
} | |
slen = 1; | |
while (slen > 0) { | |
log = lang.FlushLog(9999999); | |
slen = log.length(); | |
if (slen > 0) { | |
System.out.print(log); | |
} | |
} | |
lang._release(); | |
cx.close(); | |
} catch (GenericError e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$obFactory = New-Object -ComObject SASObjectManager.ObjectFactory | |
$obServer = New-Object -ComObject SASObjectManager.ServerDef | |
$obSAS = $obFactory.CreateObjectByServer("foobar", $true, $obServer, "", "") | |
$program = "options formchar='|----|+|---+=|-/\<>*';" | |
$program += "ods listing; proc means data=sashelp.cars mean mode min max; run;" | |
$obSAS.LanguageService.Submit($program) | |
Write-Output "Output:" | |
$list = "" | |
do | |
{ | |
$list = $obSAS.LanguageService.FlushList(1000) | |
Write-Output $list | |
} while ($list.Length -gt 0) | |
Write-Output "LOG:" | |
$log = "" | |
do | |
{ | |
$log = $obSAS.LanguageService.FlushLog(1000) | |
Write-Output $log | |
} while ($log.Length -gt 0) | |
$obSAS.Close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import win32com.client | |
username = "user" | |
password = "secret" | |
# MachineDNSName = hostname of ObjectSpawner server | |
iomhost = "host.domain.com" | |
# Port = port number on which the Workspace server is listening | |
iomport = 8591 | |
factory = win32com.client.Dispatch("SASObjectManager.ObjectFactoryMulti2") | |
serverDef = win32com.client.Dispatch("SASObjectManager.ServerDef") | |
serverDef.MachineDNSName = iomhost | |
serverDef.Port = iomport | |
serverDef.Protocol = 2 | |
serverDef.ClassIdentifier = "440196d4-90f0-11d0-9f41-00a024bb830c" | |
SASApp = factory.CreateObjectByServer("SASApp",True,serverDef,username,password) | |
program = "options formchar='|----|+|---+=|-/\<>*';" | |
program += "ods listing;proc means data=sashelp.cars mean mode min max; run;" | |
SASApp.LanguageService.Submit(program) | |
list = SASApp.LanguageService.FlushList(999999) | |
print(list) | |
log = SASApp.LanguageService.FlushLog(999999) | |
print(log) | |
SASApp.Close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Based off the SasWorkspaceExample.ps1 gist by Chris Hemedinger | |
# https://gist.github.com/cjdinger/4771455 | |
# Example of how to use Python on Windows to script the | |
# SAS Integration Technologies client | |
# You can connect to a remote SAS Workspace | |
# and run a program, retrieve the SAS Listing and Log | |
import win32com.client | |
# create the Integration Tecnologies objects | |
objFactory = win32com.client.Distpatch("SASObjectManager.ObjectFactoryMulti2") | |
# these xml files can be created using the SAS Integration Technologies Configuration utility | |
objFactory.SetMetadataFile("C:/path/to/serverinfo.xml","C:/path/to/userinfo.xml",False) | |
# create and connect to the SAS session | |
obSAS = objFactory.CreateObjectByLogicalName("SASApp - Logical Workspace Server","") | |
# program to run | |
# could be read from external file | |
program = "options formchar='|----|+|---+=|-/\<>*';" | |
program += "ods listing; proc means data=sashelp.cars mean mode min max; run;" | |
# run the program | |
objSAS.LanguageService.Submit(program) | |
# flush the output - could redirect to external file | |
list = "foo" | |
while list != "": | |
list = objSAS.LanguageService.FlushList(1000) | |
print(list) | |
# flush the log - could redirect to external file | |
log = "foo" | |
while log != "": | |
log = objSAS.LanguageService.FlushLog(1000) | |
print(log) | |
# end the SAS session | |
objSAS.Close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment