0

I am trying to add some spaces on the start of each line from os.system commands

example

os.system('pip install pyinstaller')

and then I get this

Requirement already satisfied: pyinstaller in c:\users\pc\appdata\local\programs\python\python39\lib\site-packages (5.0.1)
Requirement already satisfied: pyinstaller-hooks-contrib>=2020.6 in c:\users\pc\appdata\local\programs\python\python39\lib\site-packages (from pyinstaller) (2021.5)
Requirement already satisfied: setuptools in c:\users\pc\appdata\local\programs\python\python39\lib\site-packages (from pyinstaller) (49.2.1)
Requirement already satisfied: altgraph in c:\users\pc\appdata\local\programs\python\python39\lib\site-packages (from pyinstaller) (0.17.2)
Requirement already satisfied: pefile>=2017.8.1; sys_platform == "win32" in c:\users\pc\appdata\local\programs\python\python39\lib\site-packages (from pyinstaller) (2021.9.3)
Requirement already satisfied: pywin32-ctypes>=0.2.0; sys_platform == "win32" in c:\users\pc\appdata\local\programs\python\python39\lib\site-packages (from pyinstaller) (0.2.0)
Requirement already satisfied: future in c:\users\pc\appdata\local\programs\python\python39\lib\site-packages (from pefile>=2017.8.1; sys_platform == "win32"->pyinstaller) (0.18.2)
WARNING: You are using pip version 20.2.3; however, version 22.1.2 is available.
You should consider upgrading via the 'c:\users\pc\appdata\local\programs\python\python39\python.exe -m pip install --upgrade pip' command.

but I want to add some spaces on each line for visuals so it fits in with the rest I have looked it up many times and I have searched for hours but I can't find it pls help

2
  • Please tell us (in code) what you've already tried. Commented Jun 1, 2022 at 15:35
  • os.system() does not give you any control whatsoever over the output of the command - it's going directly to your terminal, bypassing Python completely. Use one of the functions in the subprocess module instead. Commented Jun 1, 2022 at 15:42

1 Answer 1

1

You can pipe the output to sed in the command:

os.system("pip install pyinstaller | sed 's/^/  /'")

Although as a comment mentioned, a better solution would be to use subprocess.Popen(). Then you can read the output of the command, transform it in any way you want, and then write the modified output to the terminal.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.