Problem with and windows schtasks

Tim Golden mail at
Wed Nov 21 11:01:33 CET 2012

On 20/11/2012 23:41, Tom Borkin wrote:
> Using shlex, I now have this:
> #!\Python27\python
> import os, subprocess
> path = os.path.join("C:\\", "Program Files", "Apache Group", "Apache2",
> "htdocs", "ccc", "")
>['SchTasks', '/Create', '/SC', 'ONCE', '/TN', '"test"',
> '/TR', path, '/ST', '23:50'])
>['SchTasks', '/Create', '/SC', 'ONCE', '/TN', '"test"',
> '/TR', '', '/ST', '23:50'])
> Both of the above commands throw the same error:
> ERROR: The filename, directory name or volume label syntax is incorrect.

The following works for me:

import subprocess
path = r"C:\Program Files\Apache Group\Apache2\htdocs\ccc\"[
  'SchTasks', '/Create',
  '/SC', 'ONCE',
  '/TN', 'test',
  '/TR', path,
  '/ST', '23:50'

Things to note:

* I haven't added extra quoting to any of the items in the command list
which is's first parameter. The point about using the
list (as opposed to passing an entire string which you can also do) is
that the subprocess module can quote things as needed. If you've already
added quotes, you'll get double-quoting which you almost certainly don't

* (Obviously) I've formatted the as I have for clarity,
especially via email. It's just a list.


More information about the Python-list mailing list