Hi all,
I’m calling the function below using xlWings, a Python package that integrates with Excel. As you can see below, it is supposed to create a subprocess and execute a separate python script and supply the paramaters, but it is not doing anything. To debug, I printed the full command along with parameters that is sent to the subprocess, and tried executing it in command prompt. That worked just fine.
Any idea what I’m doing wrong? I’m using Windows 10 and Python 3.9.2. Note that the path to home directory contains spaces, so I’ve been using double quotes around it.
def exitPosition():
try:
import logging, subprocess
smb = 'TSLA'
mp = getCurrentPrice()
# Place order in a subprocess
command = ['cd "full path to home directory" &', 'python', 'relative path from the home directory to the python script ', 'EXIT', smb, mp]
subprocess.Popen(command, shell=True)
return
except Exception as e:
log_file = 'Testing.log'
logging.basicConfig(filename=log_file, format='%(asctime)s - %(message)s', datefmt='%d-%b-%y %H:%M:%S', level=logging.ERROR)
logging.exception('Exception occurred')
logging.exception(e.result)