I'm using Python 2.7
I'm trying to run a StatTransfer program from Python.
When I try:
tempname = os.path.abspath('./text.txt')
TEMPFILE = open(tempname, 'wb')
try:
subprocess.check_call('ST convert.stc', shell = True, stdout = TEMPFILE, stderr = TEMPFILE)
except:
raise CritError(messages.crit_error_bad_command)
it fails (the CritError is user-defined).
The traceback doesn't tell me anything useful:
Traceback (most recent call last):
File "C:\...\py\run_program.py", line 181, in run_stcmd
run.execute_run(current_directory, posix_command, nt_command)
File "C:\...\py\private\runprogramdirective.py", line 99, in execute_run
raise CritError(messages.crit_error_bad_command)
CritError: 'ERROR! Cannot execute command'
However changing the relevant line to:
subprocess.call('ST convert.stc', shell = True, stdout = TEMPFILE, stderr = TEMPFILE)
it runs successfully.
The funny thing is, I see the same thing in my TEMPFILE for both cases:
|/-|/-|/-|/-|/- |/-|/-|/-|/-|/- Stat/Transfer - Command Processor (c) 1986-2011 Circle Systems, Inc.
www.stattransfer.com
Version 10.1.1866.0714 (32 Bit) - 64 Bit Windows
Serial: ADR4H-L3A3A-N8RJ
User: XXXXXXXXXXX
Your license is in its grace period -- Please call Circle Systems
Your program will die at the end of the month
Status: Temporarily OK (Expired May 31, 2012)
Transferring from SPSS Portable File: ..\orig\10908970\ICPSR_03775\DS0001\03775-0001- Data.por
Input file has 26 variables
Optimizing...
Transferring to Stata: ..\data\ABCFeb.dta
504 cases were transferred(0.02 seconds)
Note that if I run "st convert.stc" from the Windows command line, it runs just fine and gives me the same log message above. It does achieve what's written inside convert.stc.
This suggests that the StatTransfer program is called with subprocess.check_call. However, there's an error at the end of it. What kind of error is this? How do I avoid it? Which of the 2 commands should I use and why?
ETA: Following mgilson below, I return the value from subprocess.call and get -1. What does this mean? Why did the program still run and I didn't seem to notice any real error?
Any possible explanations and suggestions on how I should do this here?
Thanks.