I am new to SO. I am given the task of creating a windows task schedule to run a .BAT file using our Python API to push it to our fleet of remote PCs.
I am having issues with passing the arguments over to the schtask.exe.
Here is the code:
import subprocess path = "c:\windows\System32\schtasks.exe" subprocess.Popen([path, "schtasks /create /SC ONLOGON /TN 'Update_Automation_Beta' /TR 'C:\test\run_admin.bat'"], shell = True) Note: The task is just a test task right now, while I try to figure it out. Also if typed directly into command prompt window, it will work, removing the quotes etc.
schtasks. And don't useshell=True, since there's no reason to run this using cmd.exe.shlex.splitworks. On WindowsPopenhas to rebuild the list it into a string forCreateProcess, so just pass the command as a string.