Run CMD line from SPSS

Is there a way to run a Windows command prompt from SPSS?

I am working with a program that is not supported by SPEG BEGIN PROGRAM procedures, and I would like to run the command line from my SPSS syntax (I am not interested in the output, and I do not need to import / export any SPSS data, I just want to run the cmd line from SPSS )

To use a simpler example using free software, let's say I want to run an R script at the end of my SPSS syntax, but this will only work with a version not supported by SPSS (for example, at the moment SPSS 21 supports R 2.14, let's say I absolutely you need to run it on R 2.15 installed on my Windows PC), is there a way to run

R CMD BATCH C: \ Files \ MyRcode.R

in SPSS syntax?

This is equivalent to running the program (in this case R) in batch mode. The program I need to use is not R, this is just an example.

As far as I know, SPSS cannot do this, but perhaps using python (via SPSS BEGIN PROGRAM PYTHON ) can I run a command line using Python?

thanks

PS For Python users who may not have used SPSS before theoretically being able to run any Python code from SPSS using

BEGIN PROGRAM PYTHON. Run some Python code END PROGRAM. 
+4
source share
1 answer

Yes, you can do this with Python code:

 BEGIN PROGRAM PYTHON. import subprocess subprocess.call(['C:\\R\\R.exe', 'CMD', 'BATCH', 'C:\\Files\\MyRcode.R']) END PROGRAM. 

Or, directly, with this:

 HOST COMMAND=['R CMD BATCH C:\Files\MyRcode.R']. 

Alternative:

  • Put it in a batch file, then execute it, for example, using os.system() .
  • Run the Python command or Basic script using the SCRIPT command.
+4
source

All Articles