wotman
wotman

Reputation: 55

How do I make my own external command for a command-prompt?

I am making a coding language, I'm done making it now, but how do I make it like in a command prompt, and your file where you have your code inside, is called "code.scriptex", that you can type: scriptex code.scriptex?

What I mean with a command prompt: image

I've searched it up, but nothing came up, so I came here on stackoverflow to ask it!

Code of language (It's just Python lmao):

file = input()
pro = open(file,"r").read()
try:
    exec(pro)
except Exception as err:
    print(err)

I expect it to run my python file and make it work inside the command prompt. I will edit my question if something isn't clear.

Upvotes: 0

Views: 1465

Answers (1)

Vasu Deo.S
Vasu Deo.S

Reputation: 1850

Not sure, but i believe what you are trying to ask is, How to create a recognizable command in Command Prompt (CMD).

For that you have to specify the directory which contains the files (.exe for the most part) which you want to make as command in the Environment Variable:-

  1. Open My Computer, Right click and select Properties

  2. From there, select Advanced System Settings Option enter image description here

  3. A Menu will pop up, from there select Environment Variable Option enter image description here

  4. Another Menu will show up, there will be a section named System Variables in the new popup, it will contain a attribute named path in it, you have to edit that variable path by either double clickingit, or selecting path attribute and selecting editoption enter image description here

  5. A Menu named Edit Environment Variable will show up, from there select the new option enter image description here
  6. Upon selecting the new option, a input will start where you have to enter the directory of your script that you want to execute via comandline (i.e add the directory where your scriptex.exe/scriptex.py file exists)

I am using "C:\Users\vasudeos\OneDrive\Desktop\hashcat-5.1.0" directory for example

  1. Now the select OK to finalize your changes

WHAT WE DID:-

We specified path to our specific directory, in Environment variable. Now we are able to access any file, inside that directory in an abstract way (without referencing its whole path).

EXAMPLE:-

enter image description here

This is the Directory which I added in the Environment variable path, now It allows me to access any file inside this folder, without specifying its full path. (You can see my CWD is different from the directory in which my .exe is, but still i am able to execute the file)

Upvotes: 1

Related Questions