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

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <mail@timgolden.me.uk>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'syntax': 0.03; 'error:': 0.05; 'subject:skip:s 10': 0.05; 'tom': 0.07; 'filename,': 0.09; 'formatted': 0.09; 'parameter.': 0.09; 'path,': 0.09; 'throw': 0.09; 'skip:# 20': 0.13; 'passing': 0.15; "'test',": 0.16; 'do)': 0.16; 'from:addr:timgolden.me.uk': 0.16; 'from:name:tim golden': 0.16; 'message-id:@timgolden.me.uk': 0.16; 'received:74.55.86': 0.16; 'received:74.55.86.74': 0.16; 'received:smtp.webfaction.com': 0.16; 'received:webfaction.com': 0.16; 'subject:Problem': 0.16; 'subject:windows': 0.16; 'subprocess': 0.16; 'tjg': 0.16; 'string': 0.17; 'wrote:': 0.17; 'certainly': 0.17; 'module': 0.19; 'import': 0.21; 'os,': 0.22; 'needed.': 0.23; 'this:': 0.23; "haven't": 0.23; "i've": 0.23; 'command': 0.24; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; 'skip:# 10': 0.27; '(as': 0.27; 'label': 0.27; 'opposed': 0.27; 'quoting': 0.29; "skip:' 10": 0.30; 'point': 0.31; 'received:192.168.100': 0.33; 'to:addr:python-list': 0.33; 'list': 0.35; 'path': 0.35; 'especially': 0.35; 'list.': 0.35; 'skip:g 30': 0.36; 'subject:with': 0.36; 'subject:: ': 0.38; 'skip:o 20': 0.38; 'things': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'skip:" 10': 0.40; 'received:192.168': 0.40; "you've": 0.61; 'first': 0.61; "you'll": 0.62; 'note:': 0.64; 'from:addr:mail': 0.71
Date Wed, 21 Nov 2012 10:01:33 +0000
From Tim Golden <mail@timgolden.me.uk>
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20120907 Thunderbird/15.0.1
MIME-Version 1.0
To python-list@python.org
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>
In-Reply-To <CAAPnF_Ws4AKwFViG6ks=fqAzEfDdW4nRBu+g6Uk6KG9YePwVgA@mail.gmail.com>
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.135.1353492096.29569.python-list@python.org> (permalink)
Lines 38
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1353492096 news.xs4all.nl 6974 [2001:888:2000:d::a6]:32834
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:33713

Show key headers only | 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