0

Linux Mint 18.3, python 3.5.2. Is something similar to this program possible?

#!/usr/bin/env python3
import subprocess

wlist = subprocess.run(['wc', '-w'],
    stdin=subprocess.run(['ls'],stdout=subprocess.PIPE, universal_newlines=True),
    stdout=subprocess.PIPE, universal_newlines=True).stdout
print(wlist)

This can be done with separate subprocess statements, writing to and reading from disk. If it can be done in one statement, it should use less CPU, memory, and disk I/O.

  • If you are concerned about efficiency and resources, you would probably not want to call shell utilities to do things that Python library functions could probably do for you. – Kusalananda Oct 25 '19 at 22:21
  • The program snippet is just an example. The actual programs involved are user written. – rebelxt Oct 25 '19 at 23:45
  • IMHO, it's possible if you don't mind creating a new class or function. A function or class can serve as single statement, but it needs to be created first. I don't think there's anything build into Python like that. – Sergiy Kolodyazhnyy Oct 26 '19 at 01:01

0 Answers0