[英]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
? 我正在编写一种编码语言,我现在已经完成了它,但是如何在命令提示符中创建它,以及你的代码在里面的文件叫做“code.scriptex”,你可以输入:
scriptex code.scriptex
?
What I mean with a command prompt: image 我的意思是命令提示符: image
I've searched it up, but nothing came up, so I came here on stackoverflow to ask it! 我已经搜索过了,但没有出现,所以我来到stackoverflow来问它!
Code of language (It's just Python lmao): 语言代码(它只是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. 我希望它运行我的python文件,并使其在命令提示符下工作。 I will edit my question if something isn't clear.
如果不清楚,我会编辑我的问题。
Not sure, but i believe what you are trying to ask is, How to create a recognizable command in Command Prompt (CMD) . 不确定,但我相信你想要问的是,如何在命令提示符(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:- 为此,您必须指定包含要在环境变量中作为命令生成的文件(大部分为
.exe
)的目录: -
Open My Computer, Right click and select Properties
打开我的电脑,右键单击并选择
Properties
From there, select Advanced System Settings
Option 从那里,选择
Advanced System Settings
选项
A Menu will pop up, from there select Environment Variable
Option 将弹出一个菜单,从中选择
Environment Variable
选项
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 clicking
it, or selecting path attribute and selecting edit
option 另一个菜单会出现,新弹出窗口中会有一个名为
System Variables
的部分,它将包含一个名为path
的属性,你必须通过double clicking
它来编辑该变量路径,或选择路径属性并选择edit
选项
Edit Environment Variable
will show up, from there select the new option Edit Environment Variable
”的菜单,从中选择新选项 scriptex.exe
/ scriptex.py
file exists) scriptex.exe
/ scriptex.py
文件所在的目录) WHAT WE DID:- 我们做了什么:-
We specified path to our specific directory, in Environment variable. 我们在Environment变量中指定了指向特定目录的路径。 Now we are able to access any file, inside that directory in an abstract way (without referencing its whole path).
现在我们能够以抽象的方式访问该目录中的任何文件(不引用其整个路径)。
EXAMPLE:- 例:-
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) (你可以看到我的CWD与我的
.exe
所在的目录不同,但我仍然可以执行该文件)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.