Difference between os.system("clear") and os.system("cls") - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Difference between os.system("clear") and os.system("cls") (/thread-19157.html) |
Difference between os.system("clear") and os.system("cls") - chmsrohit - Jun-15-2019 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. RE: Difference between os.system("clear") and os.system("cls") - Gribouillis - Jun-15-2019 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='') RE: Difference between os.system("clear") and os.system("cls") - chmsrohit - Jun-15-2019 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. RE: Difference between os.system("clear") and os.system("cls") - noisefloor - Jun-15-2019 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 RE: Difference between os.system("clear") and os.system("cls") - DeaD_EyE - Jun-16-2019 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. RE: Difference between os.system("clear") and os.system("cls") - snippsat - Jun-16-2019 (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. RE: Difference between os.system("clear") and os.system("cls") - DeaD_EyE - Jun-16-2019 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 [attachment=669] RE: Difference between os.system("clear") and os.system("cls") - ykumar34 - Jan-11-2021 (Jun-15-2019, 02:38 PM)chmsrohit Wrote: what is the difference between os.system("clear") and os.system("cls")? 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') |