Re: Problem with subprocess.call and windows schtasks

Discussion in 'Python' started by Tim Golden, Nov 21, 2012.

  1. Tim Golden

    Tim Golden Guest

    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", "run_alert.py")
    > #subprocess.call(['SchTasks', '/Create', '/SC', 'ONCE', '/TN', '"test"',
    > '/TR', path, '/ST', '23:50'])
    > subprocess.call(['SchTasks', '/Create', '/SC', 'ONCE', '/TN', '"test"',
    > '/TR', 'run_alert.py', '/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\run_alert.py"
    subprocess.call([
    '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 subprocess.call'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
    want.

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

    TJG
    Tim Golden, Nov 21, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. cct

    schtasks problem

    cct, Nov 12, 2003, in forum: ASP .Net Security
    Replies:
    0
    Views:
    164
  2. Tim Golden
    Replies:
    0
    Views:
    173
    Tim Golden
    Nov 18, 2012
  3. Chris Rebert
    Replies:
    0
    Views:
    206
    Chris Rebert
    Nov 18, 2012
  4. Dave Angel
    Replies:
    0
    Views:
    161
    Dave Angel
    Nov 21, 2012
  5. Prasad, Ramit
    Replies:
    0
    Views:
    155
    Prasad, Ramit
    Nov 23, 2012
Loading...

Share This Page