Open text file and program shortcut in a Windows batch file

327,825

Solution 1

I was able to figure out the solution:

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

Solution 2

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"

Solution 3

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.

Solution 4

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.

Solution 5

I use

@echo off
Start notepad "filename.txt"
exit

to open the file.

Another example is

@echo off
start chrome "filename.html"
pause
Share:
327,825
Mark Ursino
Author by

Mark Ursino

...nothing to see here, move along...

Updated on August 22, 2021

Comments

  • Mark Ursino
    Mark Ursino over 2 years

    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"
    
  • Chris Geirman
    Chris Geirman over 7 years
    this is ambiguous to me. By "location of notepad file" are you referring to the notepad executable or the file to be opened in notepad?
  • Laurent B
    Laurent B about 6 years
    computerhope.com/starthlp.htm it is better to use the full syntax such as stated in the approved answser