I have problem with creating scheduled tasks with python. After executing my command, scheduled task's action part splits into argument and path slices and makes it invalid. I have tried lots of ways like "\" mypath \"" but was not successful. How can I concatenate executable's path to variable that makes scheduled task's task action valid ?
import os
import subprocess
path = os.environ['APPDATA']
filename = "test.exe"
path = path+"\\"+filename
command = 'schtasks.exe /CREATE /RU "%USERNAME%" /SC ONLOGON /TN "testServiceHello" /TR "'+path+'"'
proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
stdout_value = proc.stdout.read() + proc.stderr.read()
print stdout_value
print "--"*50
print command