I have a python script on a Windows Server called optimize.py that calls three other python scripts 4 times each using the os.system() method.
print('Creating input files for optimization algorithm...\n')
os.system("example.py 2 2 0 1")
os.system("example.py 3 3 0 1")
os.system("example.py 4 4 0 1")
os.system("example.py -1 10 0 1")
This works perfectly when I execute optimize.py myself. However, when it is executed from my ColdFusion application which is running on the same server, I get the error "Can't find a default Python" each time it tries to call example.py. The rest of the script runs just fine.
This is the ColdFusion code that is executing the python script:
<cf_exec cmd="cmd.exe">
cd C:\xxx_Optimization\
"C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\bcp.exe" [SQL_Table] out [directory] -c -t, -U [user] -P [password] -S [server]
cd C:\xxx_Optimization\pyOptimization\
python C:\xxx_Optimization\pyOptimization\optimize.py
<cfoutput>#pyUniqueZipCommand#</cfoutput>
date /t > pyDone.txt
</cf_exec>
I've already added python to the PATH, and I've also followed the answers in this post, to no avail. Can anyone tell me what I'm doing wrong here, or suggest an alternative to os.system for executing these scripts?
EDIT: I've also tried specifying the entire filepath in the OS.system methods, but I received the same error.
If the Can't find a default Python
error is only being returned when trying to call further python scripts from within the initial python script - ie if your ftype
and PATH
settings are known to be good - then the issue is with the new context, try:
os.system(sys.executable + "example.py 2 2 0 1")
or
os.system("python example.py 2 2 0 1")