Notice: Undefined offset: 6902316 in /var/www/html/qa-external/qa-external-users.php on line 744
Just at least try to help me... pls D: - OnlineGDB Q&A
Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Just at least try to help me... pls D:

+8 votes
asked Jun 2, 2025 by (6,150 points)

I've been trying to make my own terminal, and everything is fine. I've made the cd, ls, rm, rmdir, mkdir, etc... commands originally, but I want to make my terminal functional. E.g. I want a programmer to be able to find my terminal, or at least its code useful. So, I want to enable commands like nvim, python, gcc, g++  but the problem is that idk how to do that.

The 1 big problem with
if command == ...:
    ...
else:

    os.system(command)

is that if the command is invalid, both in my terminal and in powershell, it will display powershell's error, making my terminal look like just a good-looking powershell, while all my commands are original.

I have my custom error code but if I use os.system(command) and command is some gibberish like fksdhfiashgkuahe4g then it will print both "*gibberish* is not an external or batch blah blah blah" and my custom error code right below it.

SUMMARY:
i want to use e.g. gcc, g++, nvim and all that in powershell but not display its errors in my terminal, only my own.

the terminal is infact made with python, so keep that in mind

THANK YOU SO MUCH FOR TAKING YOUR TIME TO READ ALL THAT, I REALLY APPRECIATE IT <3

(i know the answer may be easy but im stupid so... yeah :3)

1 Answer

+4 votes
answered Jun 2, 2025 by (6,150 points)
 
Best answer

GOT THE ANSWER!!!

For da fellas who is in the same position as me, you can use:

import shutil

if shutil.which(command): # if command EXIST
    os.system(command) # use the command
else:
    print(...) # if command doesnt exist, print custom error.

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...