简体   繁体   English

如何为命令提示符创建自己的外部命令?

[英]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 )的目录: -

  1. Open My Computer, Right click and select Properties 打开我的电脑,右键单击并选择Properties

  2. From there, select Advanced System Settings Option 从那里,选择Advanced System Settings选项 在此输入图像描述

  3. A Menu will pop up, from there select Environment Variable Option 将弹出一个菜单,从中选择Environment Variable选项 在此输入图像描述

  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 clicking it, or selecting path attribute and selecting edit option 另一个菜单会出现,新弹出窗口中会有一个名为System Variables的部分,它将包含一个名为path的属性,你必须通过double clicking它来编辑该变量路径,或选择路径属性并选择edit选项 在此输入图像描述

  5. A Menu named Edit Environment Variable will show up, from there select the new option 将显示名为“ Edit Environment Variable ”的菜单,从中选择新选项 在此输入图像描述
  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 (ie add the directory where your scriptex.exe / scriptex.py file exists) 选择新选项后,将开始输入,您必须输入要通过comandline执行的脚本目录(即添加scriptex.exe / scriptex.py文件所在的目录)

我使用的是“C:\\ Users \\ vasudeos \\ OneDrive \\ Desktop \\ hashcat-5.1.0”目录

  1. Now the select OK to finalize your changes 现在选择确定以完成更改

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.

相关问题 使用命令提示符终端调用 python 脚本 - Invoke python script using command-prompt terminal 是否有必要使用终端/命令提示符来学习python的知识 - Is it necessary to have the knowledge of using terminal/command-prompt for learning python 如何使您的OWN控制台像Windows命令提示符 - How to make your OWN console like windows command prompt Quandl 不在 Jupyter Notebook 中工作(但在命令提示符下工作) - Quandl not working in Jupyter Notebook (but working at command-prompt) 如何将我的awk命令变成python命令 - How do i make my awk command into a python command 我应该如何在命令提示符下执行此操作? - How should I do this in command prompt? 如何在命令提示符下将 Python 3 设为我的默认 Python? - How to make Python 3 my default Python at command prompt? 如何使当前文件夹路径适用于我的命令 - How do I make the current folder path to work for my command 如何从命令提示符 window 运行我新创建的 hello_world.py 文件? - How do I run my newly created hello_world.py file from a command prompt window? 如何检测我的 Python 代码是否在 PowerShell 或命令提示符 (cmd) 中运行 - How do I detect if my python code is running in PowerShell or the Command Prompt (cmd)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM