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")
#1
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.
Reply
#2
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='')
buran likes this post
Reply
#3
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.
Reply
#4
Hi,

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
Reply
#5
clear is a linux command.
deadeye@nexus ~ $ which clear                                                                                                   
/usr/bin/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/ld-linux-x86-64.so.2, 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.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#6
(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.
Reply
#7
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.

https://aka.ms/pscore6-docs
Type 'help' to get help.

PS /home/andre> 
You can use also Visual Studio Code on Linux: https://code.visualstudio.com/download
   
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#8
(Jun-15-2019, 02:38 PM)chmsrohit Wrote: 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.

os.system('command') exacutes the os (dos/windows/linux/unix/mac etc.) command.
If the command is executed properly, it returns 0 ('No error'), otherwise it returns the error code (an integer other than 0). I think for unrecognised commands the error code is 1.

Try executing this code:
import os
a=input("Enter a number: ")
print(a)
os.system('cls')
a=input("Enter a number: ")
print(a)
os.system('clear')
a=input("Enter a number: ")
print(a)
os.system('date')
buran write Jan-11-2021, 06:46 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  FileNotFoundError: [WinError 2] The system cannot find the file specified NewBiee 2 1,495 Jul-31-2023, 11:42 AM
Last Post: deanhystad
  Os.system("shutdown"); command not found cosmin1805 4 1,617 Nov-13-2022, 02:07 PM
Last Post: cosmin1805
  [split] Please help with menu system dvejsa 4 1,233 Sep-13-2022, 08:01 PM
Last Post: dvejsa
  Alarm system with state, class, enum. Frankduc 0 1,240 May-04-2022, 01:26 PM
Last Post: Frankduc
  simulation of alarm system Frankduc 6 1,596 Apr-21-2022, 03:45 PM
Last Post: Frankduc
  Python Flask Realtime system printout (console) ffmpeg jttolleson 3 2,859 Apr-18-2022, 06:39 PM
Last Post: jttolleson
  Avoid third party functions to wrote my python code into system debug-log? mark 9 2,139 Apr-09-2022, 08:41 PM
Last Post: mark
  Help with multi-window system garynewport 3 2,175 Mar-16-2022, 03:05 AM
Last Post: deanhystad
  Advice for Inventory System Extra 0 1,282 Feb-18-2022, 09:25 PM
Last Post: Extra
  Need Help With Python RPG Battle System SBanya 1 6,426 Nov-01-2021, 10:38 PM
Last Post: Garudyne

Forum Jump:

User Panel Messages

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