Python Forum
Difference between os.system("clear") and os.system("cls")
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Difference between os.system("clear") and os.system("cls")
what is the difference between os.system("clear") and os.system("cls")?
when executed with a clear command, it returned "1" and when executed with a cls command, it returned "0".
Help me out with clear understanding.
I think 'clear' is for the Linux terminal and 'cls' is for the Windows terminal. Note that in ANSI capable terminals such as the linux terminal, you can clear the screen with
print("\033[2J\033[;H", end='')
I've executed both of the commands in windows and it worked fine without any Traceback error each giving executed results as "1" and "0" respectively. If "clear" is for Linux Terminal, I think it should throw some error when executed on Windows.

side note: os.system(whatever) is outdated and should not be used anymore. That's also clearly stated in the official Python documentation. Use the subprocess module instead.

Except this, both ways execute a command outside Python, so whatever the result is, it has nothing to do with Python. So to see what "clear" and "cls" do e.g. on Windows, you may want to consult the Windows documentation for both commands.

Regards, noisefloor
clear is a linux command.
deadeye@nexus ~ $ which clear                                                                                                   
deadeye@nexus ~ $ file /usr/bin/clear                                                                                           
/usr/bin/clear: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/, for GNU/Linux 3.2.0, BuildID[sha1]=125b29469045b30adcd4c134b9cf8e287ba13bea, stripped
deadeye@nexus ~ $  
I use always CTRL + L, if I use the terminal.

cls is and was always the command on MS-Systems to clear the screen.
The command was introduced with DOS.
So after the hell was frozen (Microsoft has a Linux Subsystem), they come closer to Linux.
They added support for SSH, Unix-Sockets. They offer different Linux Distributions for the Linux Subsystem.
They bought github. I guess the next step would be, to buy Canonical.

For compatibility reasons, you would see more and more supported GNU Linux commands on Windows.
The Powershell is on Windows, what /bin/bash is on Linux. But it's nice to have an intersection of commands in both worlds.

The return code comes from the started process itself. 0 == OK
The retval 1 comes not from 'clear', because it's not there. I think the invoked command/library/syscall
returns this value, if a command was not found. I don't use windows very often, so my knowledge how
processes on widows are started, is very limited.
My code examples are always for Python >=3.6.0
Almost dead, but too lazy to die:
All humans together. We don't need politicians!
(Jun-16-2019, 04:08 AM)DeaD_EyE Wrote: I use always CTRL + L, if I use the terminal.
Yes me to also as it work in cmder
(Jun-16-2019, 04:08 AM)DeaD_EyE Windows. Wrote: The Powershell is on Windows, what /bin/bash is on Linux.
It's still bad in my option,and not close to cmder in functionally and look,that work equal good as any Terminal shell on Linux.
All commands that used in Linux like SSH(ssh user@host), git, cat, scp, ls, find, ect.. works in cmder.
I love annoying the Windows admins with PowerShell, because most of them don't use this programming language.
I don't like PowerShell too, but if you want to use it on Linux, you can do it.

andre@andre-GP70-2PE:~$ sudo snap install powershell --classic
powershell 6.2.1 aus Microsoft PowerShell✓ installiert
andre@andre-GP70-2PE:~$ powershell 
PowerShell 6.2.1
Copyright (c) Microsoft Corporation. All rights reserved.
Type 'help' to get help.

PS /home/andre> 
You can use also Visual Studio Code on Linux:
My code examples are always for Python >=3.6.0
Almost dead, but too lazy to die:
All humans together. We don't need politicians!

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to link Sublime Text 3 Build system to Python 3.9 Using Windows 10 Fanman001 1 73 Nov-27-2020, 10:51 PM
Last Post: snippsat
  Solve system of equations Sancho_Pansa 19 495 Oct-27-2020, 08:15 AM
Last Post: Sancho_Pansa
  function call at defined system time? Holon 5 342 Oct-06-2020, 03:58 PM
Last Post: snippsat
  Solve a system of linear equations with binary variables lopeslimagabriel 3 255 Sep-24-2020, 07:09 AM
Last Post: scidam
  system of inequalities in python fiel 1 248 Sep-12-2020, 06:07 AM
Last Post: DPaul
  How could i change the python interpreter path of os.system() 12019202386 2 278 Sep-02-2020, 06:58 AM
Last Post: DeaD_EyE
  Iris-recognition System OpenCV | Help to get start Hassibayub 0 268 Apr-28-2020, 09:19 PM
Last Post: Hassibayub
  Login and Register system finndude 1 499 Apr-24-2020, 10:05 PM
Last Post: deanhystad
  Make nested system directories based on an unsorted list? koebi 0 355 Mar-25-2020, 01:14 PM
Last Post: koebi
  File system representation in a data structure Alfalfa 1 417 Dec-18-2019, 01:56 AM
Last Post: Alfalfa

Forum Jump:

User Panel Messages

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