Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: 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; 'received:209.85.223': 0.03; 'args': 0.04; 'error:': 0.05; 'subject:skip:s 10': 0.05; 'below)': 0.07; 'executed': 0.07; 'tom': 0.07; '"if': 0.09; '"my': 0.09; '__init__': 0.09; 'cmd': 0.09; 'errread,': 0.09; 'specifying': 0.09; 'cc:addr:python-list': 0.10; 'skip:# 20': 0.13; 'passing': 0.15; '"test"': 0.16; 'argument.': 0.16; 'command:': 0.16; 'errwrite)': 0.16; 'specified.': 0.16; 'subject:Problem': 0.16; 'subject:windows': 0.16; 'subprocess': 0.16; 'string': 0.17; 'wrote:': 0.17; 'directory.': 0.17; 'exists': 0.17; 'skip:g 40': 0.17; 'skip:" 30': 0.20; 'import': 0.21; 'advise.': 0.22; 'cc:2**0': 0.23; 'specified': 0.23; 'this:': 0.23; 'cc:no real name:2**0': 0.24; 'command': 0.24; 'tried': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; '(see': 0.27; 'am,': 0.27; 'skip:# 10': 0.27; 'message- id:@mail.gmail.com': 0.27; 'chris': 0.28; 'consult': 0.29; 'skip:_ 10': 0.29; 'url:python': 0.32; 'file': 0.32; 'docs': 0.33; 'yours,': 0.33; 'code:': 0.33; 'hi,': 0.33; 'received:google.com': 0.34; 'list': 0.35; 'nov': 0.35; 'path': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'url:org': 0.36; 'skip:g 30': 0.36; 'url:library': 0.36; 'subject:with': 0.36; 'execute': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'url:docs': 0.38; 'apply': 0.39; 'skip:" 10': 0.40; 'header:Received:5': 0.40; 'your': 0.60; 'remove': 0.61; 'first': 0.61; 'liked': 0.66; '[error': 0.84; 'sender:addr:chris': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=WWz1ULgpy/3QJ9zLEO1UJYMnNcrDmtGAx3OAtAOmwI0=; b=RRc644j0Zb2wN5ad4jW3z31/1JOrhGsw9A6CP1MzBpUeRmWQZ0nYEbWpyBcSD/eEbS /ZNnFHoTUrmpSERd8Z18Pd9CEVw8xIcWX5CaHmJYCr808zoP75+DP5WGw/PUd+8UM0Kd uZn7kxwDgzKVXQ5/Y7sAntpfn3XKvDdxLXphQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :x-gm-message-state; bh=WWz1ULgpy/3QJ9zLEO1UJYMnNcrDmtGAx3OAtAOmwI0=; b=YJO/n7UGSFnj4x9TMxIR869ppZ8orJnreie6UarGW0g7iFSnfDldCLtYdwRlTWh52W LM92RB1oSZmcz4VrCffAh2NCsAM+bGLawWL8SqkGU21gmaADLo89S9YgK8mQH2AWQcc0 KkNcHsTZj4WD1Gc9cehNMP1AfujEMdR7O+Dvzn4t7KTGLttDtAcDkZbT8Fx+rexCHv4I pD88lJZm+zy4n+6Jj1iixLUfdzPyjT4kMtSFTeZXpmmp3l5mBblIaB+IMnPnnOFMuaN0 Zvfv9pgiVbR77CjuWnjWDvT0HWepv02CjrYqb5YpTH4Y7qaAU4uPyBUHKqXBwmpg/tbQ VHwQ== MIME-Version: 1.0 Sender: chris@rebertia.com In-Reply-To: References: Date: Sun, 18 Nov 2012 08:39:27 -0800 X-Google-Sender-Auth: pdSrhHH2I2-BcJBNllX2gBQhe3s Subject: Re: Problem with subprocess.call and windows schtasks From: Chris Rebert To: Tom Borkin Content-Type: text/plain; charset=UTF-8 X-Gm-Message-State: ALoCoQm+QD72HMelmm+XfbEl1mrJnugkGdiTwtLaMY0ozd/wnEc05G+SYv5CcJora68ZV52ETTuO Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 61 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1353256769 news.xs4all.nl 6970 [2001:888:2000:d::a6]:59717 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:33506 On Sun, Nov 18, 2012 at 5:48 AM, Tom Borkin wrote: > Hi, > I have this code: > > #!\Python27\python > > import subprocess > #subprocess.call(['SchTasks /Create /SC ONCE /TN "My Tasks" /TR "C:/Program > Files/Apache Group/Apache2/htdocs/ccc/run_alert.py" /ST 07:50'], shell=True) > subprocess.call(['SchTasks /Create /SC ONCE /TN "test" /TR "run_alert.py" > /ST 07:50'], shell=True) > With either call, I get this error: > C:\Program Files\Apache Group\Apache2\htdocs\ccc>cron_alert_activity.py > The system cannot find the path specified. > > If I remove the ", shell=True" I get this: > C:\Program Files\Apache Group\Apache2\htdocs\ccc>cron_alert_activity.py > C:\Program Files\Apache Group\Apache2\htdocs\ccc\cron_alert_activity.py, > line 4, in > subprocess.call(['SchTasks /Create /SC ONCE /TN "test" /TR "run_alert.py" > /ST 07:50']) > File "C:\Python27\lib\subprocess.py", line 493, in call > return Popen(*popenargs, **kwargs).wait() > File "C:\Python27\lib\subprocess.py", line 679, in __init__ errread, > errwrite) > File "C:\Python27\lib\subprocess.py", line 896, in _execute_child > startupinfo) > WindowsError: [Error 2] The system cannot find the file specified > The file exists in said directory. I can execute it from the cmd prompt. Per the docs (http://docs.python.org/2/library/subprocess.html#frequently-used-arguments ): "If passing a single string [as the `args` argument], either `shell` must be True (see below) or else the string must simply name the program to be executed **without specifying any arguments.**" (emphasis mine) > So I tried this: > pgm = "SchTasks" > args = ['/Create /SC ONCE /TN "test" /TR "run_alert.py" /ST 07:50'] > #args = ['/Create', '/SC ONCE', '/TN "test"', '/TR "run_alert.py"', '/ST > 07:50'] > cmd = [pgm] > cmd.extend(args) > subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0] > but got this error: > ERROR: Invalid argument/option - <> > > If I use the other args list I get this error: > ERROR: Invalid argument/option - '/SC ONCE' > so apparently it liked the first argument. > > Please advise. Your tokenization of your command is incorrect. Consult the Note box in the docs regarding `args` tokenization, and apply it to your command: http://docs.python.org/2/library/subprocess.html#subprocess.Popen The-docs-are-your-friend-ly Yours, Chris