Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!nntp-feed.chiark.greenend.org.uk!ewrotcd!news.nosignal.org!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; 'python.': 0.02; 'received:209.85.223': 0.03; 'output': 0.04; 'root': 0.04; 'sysadmin': 0.05; 'correct.': 0.07; 'permissions': 0.07; 'raises': 0.07; 'python': 0.09; 'clean.': 0.09; 'cmd': 0.09; 'mem': 0.09; 'permissions.': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr :python-list': 0.10; '(other': 0.16; 'cc:name:python list': 0.16; 'no)': 0.16; 'sudo': 0.16; 'byte': 0.17; 'tests': 0.18; 'code.': 0.20; 'permission': 0.20; 'file.': 0.20; 'written': 0.20; 'skip:- 40': 0.21; 'posted': 0.22; 'runs': 0.22; "i'd": 0.22; 'seems': 0.23; 'somewhere': 0.24; 'cc:2**1': 0.24; 'command': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'cc:addr:gmail.com': 0.27; 'errors.': 0.27; "doesn't": 0.28; 'fine': 0.28; 'run': 0.28; 'cat': 0.29; 'steven': 0.29; "i'm": 0.29; 'waste': 0.30; 'error': 0.30; 'file': 0.32; 'running': 0.32; 'zero': 0.33; 'received:google.com': 0.34; 'thanks': 0.34; 'confirmed': 0.35; 'received:209.85': 0.35; 'created': 0.36; 'except': 0.36; 'correctly': 0.37; 'level': 0.37; 'rather': 0.37; 'received:209': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'files': 0.38; 'some': 0.38; 'nothing': 0.38; 'instead': 0.39; 'called': 0.39; 'your': 0.60; '(that': 0.62; 'more': 0.63; 'great': 0.64; 'access?': 0.84; 'oscar': 0.84; 'way...': 0.84; 'skip:/ 30': 0.91 Newsgroups: comp.lang.python Date: Mon, 17 Dec 2012 12:56:50 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=184.3.12.136; posting-account=dXBr0AoAAAA4oVLc496_o3WhhWAWHS9M References: <50cbac6d$0$29991$c3e8da3$5496439d@news.astraweb.com> <8757bcac-76ac-4b15-9410-dc61d7a8c641@googlegroups.com> User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 184.3.12.136 MIME-Version: 1.0 Subject: Re: os.system and subprocess odd behavior From: py_genetic To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: Python List , py_genetic 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: , Message-ID: Lines: 50 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1355777820 news.xs4all.nl 6969 [2001:888:2000:d::a6]:41595 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:35013 Oscar, seems you may be correct. I need to run this program as a superuser= . However, after some more tests with simple commands... I seem to be wor= king correctly from any permission level in python.... Except for the outpu= t write command from the database to a file. Which runs fine if I paste it= into the cmd line. Also, subprocess.call_check() returns clean. However,= nothing is written to the output file when called from python. so this cmd runs great from the cmd line (sudo or no) however the output fi= le in this case is owned by the sysadmin either way... not root? /usr/local/Calpont/mysql/bin/mysql --defaults-file=3D/usr/local/Calpont/mys= ql/my.cnf -u root myDB < /home/myusr/jobs/APP_JOBS/JOB_XXX.SQL > /home/myus= r/jobs/APP_JOBS/JOB_XXX.TXT When run from sudo python (other files are also created and owned by root c= orrectly) however no output is written from the db command zero byte file = only (owned by root)... returns to python with no errors. I'm sorta at a loss. I'd rather still avoid having python connect to the d= b directly or reading the data from stdout, is a waste or mem and time for = what I need. Thanks for any more thoughts. >=20 > Because of the root permissions on the file? What happens if you write >=20 > to a file that doesn't need privileged access? >=20 >=20 >=20 > Instead of running the "exact command", run the cat commands you >=20 > posted (that Steven has confirmed as working) and run them somewhere >=20 > in your user directory without root permissions. >=20 >=20 >=20 > Also you may want to use subprocess.check_call as this raises a Python >=20 > error if the command returns an error code. >=20 >=20 >=20 >=20 >=20 > Oscar