在 Windows 批处理文件中打开文本文件和程序快捷方式
我想要运行的同一文件夹中有两个文件。一个是 .txt
文件,另一个是 .exe
的程序快捷方式。我想在同一位置创建一个批处理文件来打开文本文件和快捷方式,然后关闭批处理文件(但文本文件和程序保持打开状态)。
我尝试了这个但没有运气:
open "myfile.txt"
open "myshortcut.lnk"
也不起作用:
start "myfile.txt"
start "myshortcut.lnk"
I have two files in the same folder that I'd like to run. One is a .txt
file, and the other is the program shortcut to an .exe
. I'd like to make a batch file in the same location to open the text file and the shortcut then close the batch file (but the text file and program remain open).
I tried this with no luck:
open "myfile.txt"
open "myshortcut.lnk"
Also didn't work:
start "myfile.txt"
start "myshortcut.lnk"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(14)
这也行。第一个引用对被解释为启动命令中的窗口标题名称。
This would have worked too. The first quoted pair are interpreted as a window title name in the start command.
不要在您尝试打开的文件名两边加上引号;
start "myfile.txt"
打开一个标题为myfile.txt
的新命令提示符,而start myfile.txt
打开myfile。 txt
在记事本中。如果您想要启动文件名中包含空格的控制台应用程序,则没有简单的解决方案,但对于其他应用程序,start "" "my file.txt"
可以。Don't put quotes around the name of the file that you are trying to open;
start "myfile.txt"
opens a new command prompt with the titlemyfile.txt
, whilestart myfile.txt
opensmyfile.txt
in Notepad. There's no easy solution in the case where you want to start a console application with a space in its file name, but for other applications,start "" "my file.txt"
works.打开文本文件的命令行语法为:
该命令支持的文件类型包括(但不限于):.doc、.txt、.html、.log
如果内容太长,可以添加“|” “输入文件名.txt”后显示“更多”,每屏后会暂停;要在文件结束之前结束命令,可以按住 Ctrl + C。
The command-line syntax for opening a text file is:
File types supported by this command include (but are not limited to): .doc, .txt, .html, .log
If the contents is too long, you can add "|more" after "type filename.txt", and it will pause after each screen; to end the command before the end of the file, you can hold Ctrl + C.
我用它
来打开文件。
另一个例子是
I use
to open the file.
Another example is
您还可以这样做:
C:\Users\kemp\Install\
是您的路径。 Text1.txt 是文件。You can also do:
The
C:\Users\kemp\Install\
is your PATH. The Text1.txt is the FILE.“记事本文件的位置”>记事本 文件名
C:\Users\Desktop\Anaconda>记事本 myfile
对我有用! :)
"location of notepad file" > notepad Filename
C:\Users\Desktop\Anaconda> notepad myfile
works for me! :)
在某些情况下,打开 LNK 文件时预计应用程序运行结束。
在这种情况下,最好使用以下语法(这样您就不必等待应用程序结束) ):
按照已经指示的方式打开TXT文件即可(因为notepad.exe不会中断启动命令的执行)
In some cases, when opening a LNK file it is expecting the end of the application run.
In such cases it is better to use the following syntax (so you do not have to wait the end of the application):
To open a TXT file can be in the way already indicated (because notepad.exxe not interrupt the execution of the start command)
命令
start [filename]
在我的默认文本编辑器中打开了该文件。此命令也适用于打开非 .txt 文件。
The command
start [filename]
opened the file in my default text editor.This command also worked for opening a non-.txt file.
如果您尝试打开 Chrome 或 Microsoft Word 等应用程序,请使用以下操作:
并对要打开的所有应用程序重复此操作。
PS:这将立即打开您选择的应用程序,因此不要插入太多。
If you are trying to open an application such as Chrome or Microsoft Word use this:
And repeat this for all of the applications you want to open.
P.S.: This will open the applications you select at once so don't insert too many.
尝试使用:
Try using:
其做法非常简单,
1)只需进入我们存储文件的目录
2)然后输入命令即输入filename.file_extention
例如输入 MyFile.tx
Its very simple,
1)Just go on directory where the file us stored
2)then enter command i.e. type filename.file_extention
e.g type MyFile.tx
要使用默认软件打开文件,只需键入文件路径,或者如果位于文件位置,则键入文件名。
或者
如果您想要特定的程序(例如记事本),您可以先指定它。
或
请注意,记事本通常是 .txt 的默认文本编辑器,在这种情况下,如果您的默认文件是任何 IDE 并且您只想打开 .cs/.cpp/.py 文件,则仅键入笔记本来打开 .cs/.cpp/.py 文件更有意义查看笔记本上的文件
关于批处理文件,它将以相同的方式工作,但要同时打开它们并让命令行消失,您应该使用:
因此该命令可以打开文件并立即返回到下一行。
或
最后一个仅在批处理文件位于文件的同一位置时才有效。
如果您计划使用控制台打开批处理文件并且希望控制台在最后关闭,那么您确实应该在最后一行写入 exit 。
To open a file with default software just need to type the path of the file or, if you are at the file location, the file name.
or
If you want specific program like notepad you can specify it first.
or
Note that notepad is usually default text editor for .txt, in this case would make more sense to type notebook only to open a .cs/.cpp/.py file if your default for that files is any IDE and you just want to see the file on notebook
Regarding the batch file it will work the same way but to open them at the same time and let the command line go away you should use:
So the command can open the file and return to next line immediately.
or
The last one only works if the batch file is on the same location of the files.
If you plan on using the console to open the batch file and you want the console to close at the end you should indeed write exit on last line.
如有疑问,阅读文档总是有帮助的:
为视觉学习者提供的图片:
When in doubt, it always helps to read the docs:
Picture for the visual learners:
我能够找出解决方案:
I was able to figure out the solution: