简体   繁体   English

可以在命令提示符下运行Windows批处理文件吗?

[英]Can you run Windows batch file not in a command prompt?

My programming teacher is requiring that everyone participate in the science fair this year, and now they accept computer-related projects. 我的程序设计老师要求所有人都参加今年的科学博览会,现在他们接受与计算机相关的项目。 So, knowing only one language (Windows batch), I asked if I could make some kind of text based game in batch code. 因此,我只知道一种语言(Windows批处理),问我是否可以用批处理代码制作某种基于文本的游戏。 She said that I can only write the code, but not execute it. 她说我只能编写代码,而不能执行它。

She said that if we're even caught on the command prompt, we apparently get in big trouble and never get access to a school computer for the rest of the time I'm at the high school, or something like that... Even if all the code contains is a bunch of echos and simple variables, she won't let me and my partner run it. 她说,如果我们甚至在命令提示符下被捕获,显然很麻烦,在我上高中的其余时间里,永远也无法访问学校计算机,或者类似的事情……甚至如果所有代码都包含一堆回声和简单变量,则她不会让我和我的伙伴运行它。 She also said that we must work on the project during school in her class. 她还说,我们必须在她上课的时候在该项目上工作。

So to sum all that up, she's letting me write a game/program, but I'm not allowed to test it to make sure it works in school, which will be when I'm writing it most... 因此,总而言之,她让我编写了一个游戏/程序,但不允许我对其进行测试以确保它在学校中正常运行,这是我编写最多的游戏...

So is there any way to run/test a batch script with simple echo and set /p commands without the "dangerous, black command prompt" showing up? 那么,有什么方法可以通过简单的echo运行/测试批处理脚本并设置/ p命令,而不会显示“危险的黑色命令提示符”

I think she has no idea what she's talking about, because on the board, she wrote "back script" lol 我认为她不知道自己在说什么,因为在董事会上,她写了“ back script”(笑)

A batch file runs like any other executable file by double-clicking the file within Windows. 通过在Windows中双击批处理文件,可以像其他任何可执行文件一样运行该文件。 However, because a batch file runs in a command line it immediately exits when done, so you may only see a black box for a second. 但是,由于批处理文件在命令行中运行,完成后会立即退出,因此您可能只看到黑匣子一秒钟。

If the batch file is closing too fast, or you want to read the output from the batch file you can edit the batch file and add a pause to the end of the file. 如果批处理文件的关闭速度太快,或者您想读取该批处理文件的输出,则可以编辑该批处理文件,并在文件末尾添加一个暂停。 The pause command waits for user input before continuing. 暂停命令等待用户输入,然后继续。

A .BAT file can be made into a .EXE or .COM file to keep the program's source hidden from a user. 可以将.BAT文件制成.EXE.COM文件,以使程序的源对用户隐藏。 You could use the .BAT to .EXE converter file to convert the batch files to .EXE file. 您可以使用.BAT到.EXE转换器文件将批处理文件转换为.EXE文件。 In this program you can point to the batch file you want to convert into an executable file, include additional files, change the icon of the file, and add file details. 在此程序中,您可以指向要转换为可执行文件的批处理文件,包括其他文件,更改文件的图标,以及添加文件详细信息。

For Information on Batch files, this is one of the best resource . 有关批处理文件的信息,这是最好的资源之一

Try this: 尝试这个:

@echo off
color F0
mode con lines=25 cols=60
cls
title "Notepad - MyProgram.bat"

set /P "name=What is your name? "
echo Hello %name%, glad to see you...
pause

Execute it via a double click or enter in files browser... 通过双击执行它或在文件浏览器中输入...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM