[CENTOS] Maximum number of characters in Python3 shell call (per OS)

When replacing a program written in a shell script with Python, it was necessary to call some shell commands from Python, but it seems that shell calls have different character limits for each OS, so I investigated.

Commands to be investigated

OS to be investigated

Script used for investigation

os.system()

import os
i = 100000000
n = 0
while True:
    n += i
    arg = 'b' * n
    command = 'echo "{arg}"'.format(arg=arg)
    result = os.system(command)
    if result != 0:
        if i == 1:
            break
        n -= i
        i //= 10
print("LENGTH: ", n -1 + 7) #Add echo, comma, and space

subprocess.run(shell=True)

import subprocess
i = 100000000
n = 0
while True:
    try:
        n += i
        arg = 'b' * n
        command = 'echo "{arg}"'.format(arg=arg)
        subprocess.run(command,shell=True)
    except OSError:
        if i == 1:
            break
        n -= i
        i //= 10
print("LENGTH: ", n -1 + 7) #Add echo, comma, and space

Survey results

OSX sierra (Python3.6.1) Python3 is downloaded from https://www.python.org/

command os.system subprocess.run
Maximum number of characters 260554 characters 260549 characters

Windows7 (Python3.6.1) Python3 is downloaded from https://www.python.org/

command os.system subprocess.run
Maximum number of characters 8160 characters 32733 characters

Ubuntu16.04 (Python3.5.2) Python 3 is in the standard repository

command os.system subprocess.run
Maximum number of characters 131071 characters 131071 characters

CentOS7 (Python3.6.1) Python3 installed from the IUS community repository

command os.system subprocess.run
Maximum number of characters 131071 characters 131071 characters

For subprocess.run (shell = False)

I also verified the pattern of shell = False, but I was worried that it could be investigated well, so I did not describe it above. A place where we conducted a survey in which characters are packed in the first argument

Recommended Posts

Maximum number of characters in Python3 shell call (per OS)
Project Euler # 17 "Number of Characters" in Python
Count the number of Thai and Arabic characters well in Python
Project Euler # 8 "Maximum Product in Number String" in Python
Prime number 2 in Python
Maximum likelihood estimation implementation of topic model in python
How to get the number of digits in Python
Get the size (number of elements) of UnionFind in Python
How to identify the element with the smallest number of characters in a Python list?
Find out the maximum number of characters in multi-line text stored in a data frame
Run shell commands in python
Count the number of characters in the text on the clipboard on mac
Python --Find out number of groups in the regex expression
Equivalence of objects in Python
Dynamically call methods in Python
Implementation of quicksort in Python
[Python] Let's reduce the number of elements in the result in set operations
[Python] Correlation is below a certain level ・ Maximum number of features
Get the number of readers of a treatise on Mendeley in Python
Pixel manipulation of images in Python
Run shell command / python in R
Division of timedelta in Python 2.7 series
Infinite prime number generator in Python3
MySQL-automatic escape of parameters in python
Handling of JSON files in Python
Implementation of life game in Python
Waveform display of audio in Python
Display characters like AA in python
Law of large numbers in python
Study, number guessing game in Python
Implementation of original sorting in Python
Reversible scrambling of integers in Python
Project Euler # 4 "Maximum Palindrome" in Python
Check the in-memory bytes of a floating point number float in Python
[Python] How to use list 2 Reference of list value, number of elements, maximum value, minimum value
Graph the change in the number of keyword appearances per month using pandas
[Python] Precautions when finding the maximum and minimum values in a numpy array with a small number of elements
Conversion of string <-> date (date, datetime) in Python
Maximum average number of daily visitors (large)
Project Euler # 3 "Maximum Prime Factors" in Python
Check the behavior of destructor in Python
General Theory of Relativity in Python: Introduction
Project Euler # 11 "Maximum Product in Grid" in Python
Output tree structure of files in Python
Display a list of alphabets in Python 3
Comparison of Japanese conversion module in Python3
Summary of various for statements in Python
Project Euler # 7 "1000 1st prime number" in Python
The result of installing python in Anaconda
Gang of Four (GoF) Patterns in Python
Easily graph data in shell and Python
The basics of running NoxPlayer in Python
Project Euler # 16 "Sum of Powers" in Python
Traffic Safety-kun: Recognition of traffic signs in Python
Call sudo in Python and autofill password
Summary of built-in methods in Python list
Solve the maximum subarray problem in Python
In search of the fastest FizzBuzz in Python
Call APIGateWay with APIKey in python requests
Practical example of Hexagonal Architecture in Python
Double pendulum equation of motion in python