Python Forum
Getting error from subprocess module
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting error from subprocess module
#1
I'm writing a script to log disk usage on all our hosts to a central DB server. This works fine on one host, but on a different host I'm getting an error:

Output:
# python36 Python 3.6.8 (default, Apr 25 2019, 21:02:35) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import subprocess >>> df = subprocess.run(['df','-m'], universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python3.6/site-packages/run/__init__.py", line 145, in __new__ process = cls.create_process(command, stdin, cwd=cwd, env=env, shell=shell) File "/usr/local/lib/python3.6/site-packages/run/__init__.py", line 121, in create_process shlex.split(command), File "/usr/lib64/python3.6/shlex.py", line 305, in split return list(lex) File "/usr/lib64/python3.6/shlex.py", line 295, in __next__ token = self.get_token() File "/usr/lib64/python3.6/shlex.py", line 105, in get_token raw = self.read_token() File "/usr/lib64/python3.6/shlex.py", line 136, in read_token nextchar = self.instream.read(1) AttributeError: 'list' object has no attribute 'read' >>>
Both hosts are running CentOS 7 and Python 3.6.8

Doing a little more investigation, I was able to replicate the problem on the first host by running pip3 install subprocess.run. I then ran pip3 uninstall subprocess.run on both hosts and was able to get things working again.

I was unaware that Python includes the subprocess.run module, but apparently the version installed with Pip is faulty? Can someone explain what happened here?
Reply
#2
It seems that there is a package named subprocess.run in pypi. It's probably not what you want. From your error message this package doesn't support a list as the first argument of run().
Reply
#3
(Sep-16-2019, 02:08 PM)swechsler Wrote: I was unaware that Python includes the subprocess.run module, but apparently the version installed with Pip is faulty? Can someone explain what happened here?
subprocess added the run() function in 3.5,not related to the 3-party PyPi module.
subprocess Wrote:The run() function was added in Python 3.5;
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  problem in using subprocess module akbarza 5 1,011 Sep-24-2023, 02:02 PM
Last Post: snippsat
  Question on subprocess module. knoxvilles_joker 3 2,675 Apr-11-2021, 12:51 AM
Last Post: knoxvilles_joker
  Error when running mktorrent subprocess command pythonnewbie138 4 3,832 Sep-16-2020, 01:55 AM
Last Post: pythonnewbie138
  vlc module error pythonprogrammer 1 2,863 Apr-23-2020, 04:16 AM
Last Post: Larz60+
  Python Error in subprocess.py roydianton90 1 5,577 Dec-14-2018, 11:26 AM
Last Post: jeanMichelBain
  OS command via python subprocess module alinaveed786 21 10,809 Oct-23-2018, 05:40 AM
Last Post: alinaveed786
  subprocess error : The system cannot find the file specified evilcode1 0 10,692 Oct-03-2018, 08:04 AM
Last Post: evilcode1
  pyhton error there is no PIL module error help! pokeboss235 1 2,901 Feb-22-2018, 03:03 AM
Last Post: Larz60+
  How to get the program's pid which is running with subprocess module? purecode 1 11,983 Jan-24-2018, 04:22 AM
Last Post: wavic
  I have problem on Communication between C++ and Python using subprocess Module hlfan1234567 0 4,233 Jul-09-2017, 04:34 PM
Last Post: hlfan1234567

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020