Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open text file and program shortcut in a Windows batch file

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" 
like image 454
Mark Ursino Avatar asked Jul 11 '11 23:07

Mark Ursino


People also ask

Can a batch file open a shortcut?

If you want to use a custom file icon for your batch file, we recommend using a shortcut. Right-click the desktop and select New > Shortcut. Choose a location, ideally the same as your batch file, and click Next. Then enter a name for the shortcut and click Finish.

How do you open a file with a specific program in CMD?

Type "start [filename.exe]" into Command Prompt, replacing "filename" with the name of your selected file. Replace "[filename.exe]" with your program's name. This allows you to run your program from the file path.

How do I open a batch file in text?

To open the BAT file in Notepad, right-click it and choose Show more options > Edit from the menu (or just Edit in some Windows versions). You might find it helpful to use more advanced text editors that support syntax highlighting when editing a BAT file.

How do I open a text file in Windows command prompt?

In the Windows Command shell, type is a built in command which displays the contents of a text file. Use the type command to view a text file without modifying it. In PowerShell, type is a built-in alias to the Get-Content cmdlet, which also displays the contents of a file, but using a different syntax.

How to start Windows programs and programs from a batch file?

How to start Windows files and programs from a batch file. To run Microsoft Windows programs or file, use the START command. The example below would run Windows Notepad. You can also specify the direct location of the file by typing the following command.

How do I start a text file in Windows?

To start a Windows file, use the start command followed by the name of the file. In the example below, we have a start command that is starting the chdown.txt file in the default text editor and then also sounding an alarm MP4 audio file in the default media player. start chdown.txt && alarm.mp4.

How do I create a shortcut to a file in Windows?

Browse to where the file is stored and right click and drag the file to the desktop. Because you right clicked a menu will open with create short cut here option. Select that and the shortcut will be created. Right click on the icon and select properties to open a settings dialogue box.

Can I use the start command to open a file?

As long as Windows knows how to open a file, you can use the start command with any file. For example, you could use the start command to open a movie file, video file, Word document, Excel file, and any other file. How to make a batch file. See the start command for further information. Batch file help.


2 Answers

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" 
like image 38
foxidrive Avatar answered Oct 21 '22 06:10

foxidrive


I was able to figure out the solution:

start notepad "myfile.txt" "myshortcut.lnk" exit 
like image 156
Mark Ursino Avatar answered Oct 21 '22 07:10

Mark Ursino