Windows cmd open file with program

How to Open a File/Folder in Command Prompt (CMD) Windows 10 [MiniTool News]

By Alisa | Follow | Last Updated December 31, 2020

Summary :

Wonder how to open a file cmd or how to open a folder in Command Prompt on Windows 10? This tutorial provides a step-by-step guide. Also, if you can’t find some files or folders in Windows 10, or some files are unexpectedly lost in your Windows 10 computer, MiniTool free data recovery software for Windows 10/8/7 can help you easily recover lost files.

You can also open files from Command Prompt. Wonder how to open a file or folder in Command Prompt on Windows 10? Check the step-by-step guide in this tutorial.

How to Open a File CMD Windows 10 in 2 Steps

Step 1 – Open Command Prompt

You can press Windows + R keys on the keyboard to open Windows Run dialog. Then type cmd in the Run box. If you want to run Command Prompt as Administrator, you need to press Ctrl + Shift + Enter keys at the same time.

Alternatively, you can also click Start or Search box in Windows 10, and type cmd or command prompt. Right-click the Command Prompt app in the list and choose Run as administrator.

Step 2 – Open Files from Command Prompt

Normally you have two ways to open a file using cmd. One is to move the folder that the file is in, the other is to open the files directly in Command Prompt.

Method 1. How to open a file with cmd by moving to the folder firstly

  • You can use the cd command to move to the exact folder the file lies in. For instance, cd C:\Users\mini\Desktop.
  • After you are in the correct folder path, you can type the name of the file with its extension, e.g. “travel.png”, and hit Enter button to open it.

Windows 10 repair, recovery, reboot, reinstall, restore solutions. Learn how to create Windows 10 repair disk, recovery disk/USB drive/system image to repair Windows 10 OS issues.

Method 2. How to open a file using cmd directly

You can also choose to open files from Command Prompt on Windows 10 directly, instead of going to the folder path. You can input the full path, file name and its file extension to open the target file, e.g. “C:\Users\mini\Desktop\travel.png”.

You can also freely specify an app to open the file. You need to type the whole path of the app ahead of the path of the file. For example, C:\Users\mini\”%windir%\system32\mspaint.exe” “C:\Users\mini\Desktop\travel.png”.

How to Open a Folder in Command Prompt Windows 10

You can also open a folder from Command Prompt with the command line below.

After you enter into Command Prompt window by following the operation above, you can open a folder in File Explorer in Command Prompt. The command line can be like this, start %windir%\explorer.exe “C:\Users\mini\Desktop”.

Tip: Need to mention that you need to enclose the path of a file or folder in double quotation marks, since some folder or files names have spaces in them.

Читайте также:  Google fit для windows

To Recover Unexpectedly Lost Files or Folders in Windows 10

Sometimes you may suffer unexpected data loss in Windows 10 due to various reasons, e.g. system crash, Blue Screen error (e.g. Bad Pool Caller BSOD error), power outage, malware/virus infection, hard drive failure, etc. To easily recover lost data for free, you can choose the best free data recovery software to realize it.

MiniTool Power Data Recovery, a 100% clean and free data recovery software for Windows 10/8/7, enables you to easily recover mistakenly deleted files or lost files from computer local drive, external hard drive, SSD drive, USB drive (pen drive data recovery), SD card, and more.

Easy 3 steps to fast recover my files/data for free with best free file recovery software. 23 FAQs and solutions for how to recover my files and lost data are included.

  • Facebook
  • Twitter
  • Linkedin
  • Reddit

ABOUT THE AUTHOR

Position: Columnist

Alisa is a professional English editor with 4-year experience. She loves writing and focuses on sharing detailed solutions and thoughts for computer problems, data recovery & backup, digital gadgets, tech news, etc. Through her articles, users can always easily get related problems solved and find what they want. In spare time, she likes basketball, badminton, tennis, cycling, running, and singing. She is very funny and energetic in life, and always brings friends lots of laughs.

how to open a program using command prompt?

I followed the following

The command I used is: Start «dBox» «C:\Program Files (x86)\Dropbox\Client\Dropbox.exe»

I would expect to have a new cmd windows with title dBox which is gonna open my program. It does nothing, no message..

They suggest the same things on other website. Some suggest removing the » for the second parameter, however I have spaces in the path so it is not suggested.

I cannot see what I do wrong?

2 Answers 2

If you specifically want a new cmd window with that specific title, from which your program is run, you may try the following:

start «dBox» cmd | «c:\program files (x86)\dropbox\client\dropbox.exe»

start «dBox» cmd | (start /d «c:\program files (x86)\dropbox\client» dropbox.exe)

I don’t have DropBox installed, but this works for other executables, so it should work for you.

Walking through the code, what you want first of all is a new command window, and running the DropBox executable is subsequent to that, so let’s at least see how to get a new cmd window with your title going: start «dBox» cmd

Now, how do we repeat that while also getting another executable to run from that window? This is where the «|» (pipe) symbol comes into play, which is for redirection. The documentation says that the output from the command on the left is piped into the command on the right. We want a new process started from a new cmd window, and the only way I’ve been able to get that to work (seemingly so, anyway) is by using start twice.

You can read more about redirection here.

Edit: The first command is crossed out because I realized it made the process a child of the original cmd window. The giveaway is that the original cmd window is unusable until the child process is killed. I can’t confirm, at the moment, if the second command does the trick exactly as stated in the question.

BAT file: Open new cmd window and execute a command in there

I’m trying to open a new command window in a BAT file:

Читайте также:  Как продавать windows oem

After it opens, I’d like to execute a BAT command in the new window:

How can I do this?

8 Answers 8

You may already find your answer because it was some time ago you asked. But I tried to do something similar when coding ror. I wanted to run «rails server» in a new cmd window so I don’t have to open a new cmd and then find my path again.

What I found out was to use the K switch like this:

start before «cmd» will open the application in a new window and «/K» will execute «echo Hello, World!» after the new cmd is up.

You can also use the /C switch for something similar.

This will then execute «pause» but close the window when the command is done. In this case after you pressed a button. I found this useful for «rails server», then when I shutdown my dev server I don’t have to close the window after.

Use the following in your batch file:

/c Carries out the command specified by string and then terminates
/k Carries out the command specified by string but remains

Consult the cmd.exe documentation using cmd /? for more details.

The proper formating of the command string gets a little more complicated with spaces in the arguments. See the examples below. Note the use of nested double quotes in some examples.

Examples:

Run a program and pass a filename parameter:
CMD /c write.exe c:\docs\sample.txt

Run a program and pass a long filename:
CMD /c write.exe «c:\sample documents\sample.txt»

Spaces in program path:
CMD /c «»c:\Program Files\Microsoft Office\Office\Winword.exe»»

Spaces in program path + parameters:
CMD /c «»c:\Program Files\demo.cmd»» Parameter1 Param2
CMD /k «»c:\batch files\demo.cmd» «Parameter 1 with space» «Parameter2 with space»»

Launch demo1 and demo2:
CMD /c «»c:\Program Files\demo1.cmd» & «c:\Program Files\demo2.cmd»»

This is not very easy.

The best approach is to have the part of your script that you want to be executed in a «new window» to be in a separate .bat file. This might be impractical if e.g. you need a lot of state from the rest of your script (variables, etc). One option is to pass any values you need (e.g. dir to operate in) to the batch file:

If you have a large amount of state to transmit you might consider generating a batch file at runtime:

Obviously this is a trivial example.

The above answers helped me. But still required some figuring out. Here is an example script I use to start 3 processes for web development. It results in 3 windows staying open, as they need to run continously.

Mongo is globally added to my path, so I don’t need to cd like I do for the other two programs. Of course the path to your files will vary, but hopefully this will help.

Thanks to all here in Stack Overflow; this solution solves the above question but is extended to automatically run these tasks:

  1. I want to run my rails server
  2. Run a rake jobs:worker for my delayed_job gem too
  3. and Open default internet browser to show my page
  4. finally, to leave a cmd window open for any extra commands during my session.

I guess my project is called «antiquorum.»

Create an «init.bat» file in your %USERPROFILE% directory (open a cmd window and take a look at the path to the left of the cursor to know what %USERPROFILE% is)

In a new command line window type: C:> init antiquorum

The code opens two more cmd windows and a browser. TIMEOUT avoids errors in the browser.

Читайте также:  Запуск vs code linux

The :start section does the work. You can run tasks 1,2 or 4 separately by typing params as: server, worker, or none to leave a cmd opened in root of «antiquorum» project.

Open file from the command line on Windows

On Mac OS X and GNOME on Linux, there are commands that can be used to open files from the command line in their associated GUI editors: open and gnome-open , respectively. Is there any command like this for Windows?

9 Answers 9

If you are currently in the command prompt and have a file called test.png and , which are located in c:\test you can do the following:

If you are at the directory (so should say c:\test> ) just type:

which would open test in the default png picture editor.

If the files name contains spaces, then simply enclose the file name within » «

You can alternatively type:

which will open the file no matter where you currently are.

Finally, you can pass the picture to another program. For example, if you have an image editor called imageedit.exe and it supports opening files through command lines (and if the program is pathed/accessible or you are in it’s current directory), you can type the following:

If it is a registered extension, you can use «start» as in

On DOS command-line explorer «

» will open the file path with Windows default associated programs. This will also handle all URIs ( http:,https:,ftp: ) and other file protocols defined in Windows Operating System. If the file or protocol is not associated with any program then an Open With dialog will show up. If file is not present then default My Documents folder will open up. It can also open executable files ( EXE, BAT files) and shell namespace paths.

Examples

explorer «http://www.google.com» — will open http://www.google.com in windows default browser.

explorer «file:///C:\temp\» will open temp directory if present

explorer «file.txt» will open file.txt on the current directory path .i.e. %CD% path

You can refer about explorer’s other useful command-line switches here

Simple and versatile.

The first parameter of Start is a window title, so if you have a space in the file name, and you type

Start «My File.txt»

you’ll get a command line window with «My File.txt» as the title. To get around this use a dummy title,

Start «my title» «My File.txt»

Depending on the file and what application is opened there probably won’t be a window to see anyway.

If you are in PowerShell (at the PS (current-directory) > prompt), and you want to open a file in the current directory, you may try this .\myfile.ext . If you are in the Command Prompt, you can accomplish the same result by typing

(You must include the .\ , as PowerShell doesn’t load files from the current location by default.) Or you can provide a directory name (relative or absolute) if the file isn’t in the current directory.

For the first scenario — if you are in PowerShell — if the filename contains space(s), enclose it in quotes (either kind) and precede it with the & symbol:

(You may add a space after the & for readability, if you prefer readability, and you may use / instead of \ .) I don’t know how to make this work in the second scenario (in which you are running powershell -c from Command Prompt) if the file or directory name contains space(s) — quotes don’t seem to help.

Оцените статью