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


Groups > comp.lang.python > #35013

Re: os.system and subprocess odd behavior

Newsgroups comp.lang.python
Date 2012-12-17 12:56 -0800
References <bb08fc10-85f0-4003-a1fb-cdc449299d19@googlegroups.com> <50cbac6d$0$29991$c3e8da3$5496439d@news.astraweb.com> <8757bcac-76ac-4b15-9410-dc61d7a8c641@googlegroups.com> <mailman.970.1355764606.29569.python-list@python.org>
Subject Re: os.system and subprocess odd behavior
From py_genetic <conor.robinson@gmail.com>
Message-ID <mailman.990.1355777820.29569.python-list@python.org> (permalink)

Show all headers | View raw


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 working correctly from any permission level in python.... Except for the output 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 file in this case is owned by the sysadmin either way... not root?

/usr/local/Calpont/mysql/bin/mysql --defaults-file=/usr/local/Calpont/mysql/my.cnf -u root myDB < /home/myusr/jobs/APP_JOBS/JOB_XXX.SQL > /home/myusr/jobs/APP_JOBS/JOB_XXX.TXT


When run from sudo python (other files are also created and owned by root correctly)  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 db directly or reading the data from stdout, is a waste or mem and time for what I need.

Thanks for any more thoughts.

> 
> Because of the root permissions on the file? What happens if you write
> 
> to a file that doesn't need privileged access?
> 
> 
> 
> Instead of running the "exact command", run the cat commands you
> 
> posted (that Steven has confirmed as working) and run them somewhere
> 
> in your user directory without root permissions.
> 
> 
> 
> Also you may want to use subprocess.check_call as this raises a Python
> 
> error if the command returns an error code.
> 
> 
> 
> 
> 
> Oscar

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


Thread

os.system and subprocess odd behavior py_genetic <conor.robinson@gmail.com> - 2012-12-14 10:13 -0800
  Re: os.system and subprocess odd behavior Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-12-14 22:47 +0000
    Re: os.system and subprocess odd behavior py_genetic <conor.robinson@gmail.com> - 2012-12-17 08:39 -0800
      Re: os.system and subprocess odd behavior Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-12-17 17:16 +0000
        Re: os.system and subprocess odd behavior py_genetic <conor.robinson@gmail.com> - 2012-12-17 12:56 -0800
          Re: os.system and subprocess odd behavior Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-12-18 00:01 +0000
            Re: os.system and subprocess odd behavior py_genetic <conor.robinson@gmail.com> - 2012-12-18 10:26 -0800
              Re: os.system and subprocess odd behavior Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-12-18 18:52 +0000
                Re: os.system and subprocess odd behavior py_genetic <conor.robinson@gmail.com> - 2012-12-18 12:52 -0800
                Re: os.system and subprocess odd behavior py_genetic <conor.robinson@gmail.com> - 2012-12-18 12:52 -0800
            Re: os.system and subprocess odd behavior py_genetic <conor.robinson@gmail.com> - 2012-12-18 10:26 -0800
          Re: os.system and subprocess odd behavior Hans Mulder <hansmu@xs4all.nl> - 2012-12-18 23:46 +0100
        Re: os.system and subprocess odd behavior py_genetic <conor.robinson@gmail.com> - 2012-12-17 12:56 -0800
  Re: os.system and subprocess odd behavior Dieter Maurer <dieter@handshake.de> - 2012-12-15 08:12 +0100
    Re: os.system and subprocess odd behavior py_genetic <conor.robinson@gmail.com> - 2012-12-17 08:30 -0800
    Re: os.system and subprocess odd behavior py_genetic <conor.robinson@gmail.com> - 2012-12-17 08:30 -0800
  Re: os.system and subprocess odd behavior photonymous@gmail.com - 2012-12-17 21:10 -0800
    Re: os.system and subprocess odd behavior Hans Mulder <hansmu@xs4all.nl> - 2012-12-18 11:27 +0100
      Re: os.system and subprocess odd behavior Dave Angel <d@davea.name> - 2012-12-18 05:39 -0500
        Re: os.system and subprocess odd behavior Hans Mulder <hansmu@xs4all.nl> - 2012-12-18 12:40 +0100

csiph-web