Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #33713

Re: Problem with subprocess.call and windows schtasks

Date 2012-11-21 10:01 +0000
From Tim Golden <mail@timgolden.me.uk>
Subject Re: Problem with subprocess.call and windows schtasks
References <CAAPnF_W4XWNLzC=qaAjsHF8MDY574x6UA=ewE3Jw=ZksvnXjJg@mail.gmail.com> <CAMZYqRRJsMtQQVkkH7quQGsrmsWmtQhaNLR9t5_eD7pdrmRq3w@mail.gmail.com> <CAAPnF_Ws4AKwFViG6ks=fqAzEfDdW4nRBu+g6Uk6KG9YePwVgA@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.135.1353492096.29569.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Problem with subprocess.call and windows schtasks Tim Golden <mail@timgolden.me.uk> - 2012-11-21 10:01 +0000

csiph-web