Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Production Facility (stats.com) instead of SpssClient to run .sps #1

Open
fomcl opened this issue Sep 4, 2017 · 0 comments
Open

Comments

@fomcl
Copy link

fomcl commented Sep 4, 2017

Hi,

From the readme: "To use the run selected code in SPSS tool
1.Make sure you have SPSS already running"

If you use the Production Facility, you only use a costly license when you actually run the .sps.
The Production Facility takes an .spj while (which is actually an .xml file) that itself calls one of more .sps files. When you're done, you can use the free smartreader to view the output (.spv).

Code fragment:

stats = r"C:\PROGRA~1\IBM\SPSS\STATIS~1\22\stats.com"
reader = r"C:\PROGRA~1\IBM\SPSS\Smartreader\21\reader.exe"

# this has the locale and locale/codepage  setting hard-coded. Not nice, but good enough for my purposes
def create_spj(syntaxPath, outputPath, productionPath):
    """create the SPSS production facility file (.spj)"""
    spj_template = '''\
    <job xmlns="http://www.ibm.com/software/analytics/spss/xml/production"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" print="false"
      syntaxErrorHandling="continue" syntaxFormat="interactive" unicode="false"
      xsi:schemaLocation="http://www.ibm.com/software/analytics/spss/xml/production
      http://www.ibm.com/software/analytics/spss/xml/production/production-1.4.xsd">
      <locale charset="windows-1252" country="NL" language="nl"/>
      <output outputFormat="viewer" outputPath="%(outputPath)s"/>
      <syntax syntaxPath="%(syntaxPath)s"/>
    </job>'''
    logger.debug("create .spj:" + spj_template % locals())
    with open(productionPath, "w") as f:
        f.write(spj_template % locals())

def run_production_facility(stats, productionPath):
    """run the SPSS production facility"""
    cwd = dirname(abspath(productionPath))
    cmds = [stats, "-production", "silent", "-nologo", productionPath]
    logger.info(".spj runnen: %s", " ".join(cmds))
    proc = Popen(cmds, cwd=cwd, stdout=PIPE, stderr=PIPE)
    #proc.wait()
    proc.communicate()
    errors = proc.stderr.read()
    if errors:
        logger.error(error)
    output = proc.stdout.read()
    if output:
        logger.warning(output)

if __name__ == '__main__':
    create_spj(syntaxPath, outputPath, productionPath)
    run_production_facility(stats, productionPath)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant