Inspired by this question and answer I wrote a simple "set current working directory". But sometimes it throws this error:
>Warning # 6894. Command name: BEGIN PROGRAM
>The external program exit unexpectedly and lost its content, a new exteranl
>program will startup to execute the rest of job.
I cannot lead this error to anything special in my code, SPSS throws this error sometimes, if I keep executing the program sometimes it works and sometimes it does not with above error, so it feels like if the client sometimes is not started or something. My program looks like this:
def Run(args):
import spss, spssaux, SpssClient, os
SpssClient.StartClient()
my_filepath_ = os.path.dirname(SpssClient.GetDesignatedSyntaxDoc().GetDocumentPath())
my_filepath = spssaux._smartquote(my_filepath_)
spss.Submit("CD %s ." % (my_filepath))
SpssClient.StopClient()
I have also set up a XML file and placed it along with the python file in the EXTPATHS EXTENSIONS directory.
<Command xmlns="http://xml.spss.com/extension" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="SET_CWD" Language="Python">
</Command>
It is called by typing SET_CWD
in a syntax file, SET_CWD
is also the name of the .py- and .xml-file, SET_CWD.py
and SET_CWD.xml
.