在 Windows 批处理文件中打开文本文件和程序快捷方式

发布于 2024-11-23 15:53:30 字数 306 浏览 4 评论 0原文

我想要运行的同一文件夹中有两个文件。一个是 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(14

深海夜未眠 2024-11-30 15:53:31

这也行。第一个引用对被解释为启动命令中的窗口标题名称。

start "" "myfile.txt"
start "" "myshortcut.lnk"

This would have worked too. The first quoted pair are interpreted as a window title name in the start command.

start "" "myfile.txt"
start "" "myshortcut.lnk"
渔村楼浪 2024-11-30 15:53:31

不要在您尝试打开的文件名两边加上引号; 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 title myfile.txt, while start myfile.txt opens myfile.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.

最美的太阳 2024-11-30 15:53:31

打开文本文件的命令行语法为:

type filename.txt

该命令支持的文件类型包括(但不限于):.doc、.txt、.html、.log

如果内容太长,可以添加“|” “输入文件名.txt”后显示“更多”,每屏后会暂停;要在文件结束之前结束命令,可以按住 Ctrl + C

The command-line syntax for opening a text file is:

type filename.txt

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.

当爱已成负担 2024-11-30 15:53:31

我用它

@echo off
Start notepad "filename.txt"
exit

来打开文件。

另一个例子是

@echo off
start chrome "filename.html"
pause

I use

@echo off
Start notepad "filename.txt"
exit

to open the file.

Another example is

@echo off
start chrome "filename.html"
pause
迷乱花海 2024-11-30 15:53:31

您还可以这样做:

start notepad "C:\Users\kemp\INSTALL\Text1.txt"

C:\Users\kemp\Install\ 是您的路径。 Text1.txt 是文件。

You can also do:

start notepad "C:\Users\kemp\INSTALL\Text1.txt"

The C:\Users\kemp\Install\ is your PATH. The Text1.txt is the FILE.

久光 2024-11-30 15:53:31

“记事本文件的位置”>记事本 文件名

C:\Users\Desktop\Anaconda>记事本 myfile

对我有用! :)

"location of notepad file" > notepad Filename

C:\Users\Desktop\Anaconda> notepad myfile

works for me! :)

破晓 2024-11-30 15:53:31

在某些情况下,打开 LNK 文件时预计应用程序运行结束。

在这种情况下,最好使用以下语法(这样您就不必等待应用程序结束) ):

START /B /I "MyTitleApp" "myshortcut.lnk"

按照已经指示的方式打开TXT文件即可(因为notepad.exe不会中断启动命令的执行)

START notepad "myfile.txt"

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):

START /B /I "MyTitleApp" "myshortcut.lnk"

To open a TXT file can be in the way already indicated (because notepad.exxe not interrupt the execution of the start command)

START notepad "myfile.txt"
你的背包 2024-11-30 15:53:31

命令 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.

梦屿孤独相伴 2024-11-30 15:53:31

如果您尝试打开 Chrome 或 Microsoft Word 等应用程序,请使用以下操作:

@echo off
start "__App_Name__" "__App_Path__.exe"

并对要打开的所有应用程序重复此操作。

PS:这将立即打开您选择的应用程序,因此不要插入太多。

If you are trying to open an application such as Chrome or Microsoft Word use this:

@echo off
start "__App_Name__" "__App_Path__.exe"

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.

呆头 2024-11-30 15:53:31

尝试使用:

@ECHO off
ECHO Hello World!

START /MAX D:\SA\pro\hello.txt

Try using:

@ECHO off
ECHO Hello World!

START /MAX D:\SA\pro\hello.txt
流心雨 2024-11-30 15:53:31

其做法非常简单,
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

弱骨蛰伏 2024-11-30 15:53:31

要使用默认软件打开文件,只需键入文件路径,或者如果位于文件位置,则键入文件名。

C:\Users\MyName>C:\User\MyName\Desktop\hello.txt

或者

C:\Users\MyName\Desktop>hello.txt

如果您想要特定的程序(例如记事本),您可以先指定它。

C:\Users\MyName>notepad C:\User\MyName\Desktop\hello.txt

C:\Users\MyName\Desktop>notepad hello.txt

请注意,记事本通常是 .txt 的默认文本编辑器,在这种情况下,如果您的默认文件是任何 IDE 并且您只想打开 .cs/.cpp/.py 文件,则仅键入笔记本来打开 .cs/.cpp/.py 文件更有意义查看笔记本上的文件

关于批处理文件,它将以相同的方式工作,但要同时打开它们并让命令行消失,您应该使用:

start "title" {filename}

因此该命令可以打开文件并立即返回到下一行。

start "" C:\Users\MyName\MyFolder\foo.exe
start "" C:\Users\MyName\MyFolder\notes.txt

start "" foo.exe
start "" notes.txt

最后一个仅在批处理文件位于文件的同一位置时才有效。

如果您计划使用控制台打开批处理文件并且希望控制台在最后关闭,那么您确实应该在最后一行写入 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.

C:\Users\MyName>C:\User\MyName\Desktop\hello.txt

or

C:\Users\MyName\Desktop>hello.txt

If you want specific program like notepad you can specify it first.

C:\Users\MyName>notepad C:\User\MyName\Desktop\hello.txt

or

C:\Users\MyName\Desktop>notepad hello.txt

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:

start "title" {filename}

So the command can open the file and return to next line immediately.

start "" C:\Users\MyName\MyFolder\foo.exe
start "" C:\Users\MyName\MyFolder\notes.txt

or

start "" foo.exe
start "" notes.txt

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.

糖果控 2024-11-30 15:53:31

如有疑问,阅读文档总是有帮助的:

>help start


Starts a separate window to run a specified program or command.

START ["title"] [/D path] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED]
      [/LOW | /NORMAL | /HIGH | /REALTIME | /ABOVENORMAL | /BELOWNORMAL]
      [/NODE <NUMA node>] [/AFFINITY <hex affinity mask>] [/WAIT] [/B]
      [command/program] [parameters]

    "title"     Title to display in window title bar.
    path        Starting directory.
    B           Start application without creating a new window. The
                application has ^C handling ignored. Unless the application
                enables ^C processing, ^Break is the only way to interrupt
                the application.
    I           The new environment will be the original environment passed
                to the cmd.exe and not the current environment.
    MIN         Start window minimized.
    MAX         Start window maximized.
    SEPARATE    Start 16-bit Windows program in separate memory space.
    SHARED      Start 16-bit Windows program in shared memory space.
    LOW         Start application in the IDLE priority class.
    NORMAL      Start application in the NORMAL priority class.
    HIGH        Start application in the HIGH priority class.
    REALTIME    Start application in the REALTIME priority class.
    ABOVENORMAL Start application in the ABOVENORMAL priority class.
    BELOWNORMAL Start application in the BELOWNORMAL priority class.
    NODE        Specifies the preferred Non-Uniform Memory Architecture (NUMA)
                node as a decimal integer.
    AFFINITY    Specifies the processor affinity mask as a hexadecimal number.

为视觉学习者提供的图片:
帮助开始

When in doubt, it always helps to read the docs:

>help start


Starts a separate window to run a specified program or command.

START ["title"] [/D path] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED]
      [/LOW | /NORMAL | /HIGH | /REALTIME | /ABOVENORMAL | /BELOWNORMAL]
      [/NODE <NUMA node>] [/AFFINITY <hex affinity mask>] [/WAIT] [/B]
      [command/program] [parameters]

    "title"     Title to display in window title bar.
    path        Starting directory.
    B           Start application without creating a new window. The
                application has ^C handling ignored. Unless the application
                enables ^C processing, ^Break is the only way to interrupt
                the application.
    I           The new environment will be the original environment passed
                to the cmd.exe and not the current environment.
    MIN         Start window minimized.
    MAX         Start window maximized.
    SEPARATE    Start 16-bit Windows program in separate memory space.
    SHARED      Start 16-bit Windows program in shared memory space.
    LOW         Start application in the IDLE priority class.
    NORMAL      Start application in the NORMAL priority class.
    HIGH        Start application in the HIGH priority class.
    REALTIME    Start application in the REALTIME priority class.
    ABOVENORMAL Start application in the ABOVENORMAL priority class.
    BELOWNORMAL Start application in the BELOWNORMAL priority class.
    NODE        Specifies the preferred Non-Uniform Memory Architecture (NUMA)
                node as a decimal integer.
    AFFINITY    Specifies the processor affinity mask as a hexadecimal number.

Picture for the visual learners:
help start

很糊涂小朋友 2024-11-30 15:53:30

我能够找出解决方案:

start notepad "myfile.txt"
"myshortcut.lnk"
exit

I was able to figure out the solution:

start notepad "myfile.txt"
"myshortcut.lnk"
exit
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文