Andrei20193
Andrei20193

Reputation: 469

How do I launch a program from command line without opening a new cmd window?

I'm trying to programmatically execute an external file from cmd using this command:

START "filepath"

Where "filepath" is the path of my file. It opens fine but it also open a new command prompt window.

So, which is the right command for opening an external program without opening a new window?

Upvotes: 30

Views: 245890

Answers (10)

Christopher
Christopher

Reputation: 3647

It's easier and safer to use the explorer.exe to start files/executeables, it is also opening files with the associated program and runs executables directly, if you execute:

start "" "%windir%\explorer.exe" "C:\Path\To\some.pdf"

If *.PDF files are not associated with any program. This works similar to a double-click and triggers the "open with program" dialog.

start "" "%windir%\explorer.exe" "%windir%\system32\calc.exe"

Will bring up the calculator.

start "" "%windir%\explorer.exe" "C:\pagefile.sys"

Will bring up a warning like: You are trying to open a system file (*.sys)... choose a programm...

Important

explorer.exe always requires the full path to the executable/file, not the relative path. If you want to use relative paths, use

start "" "%windir%\explorer.exe" "relative\file.pdf","C:\dir\"

Security related

Using start "" "some\file.dat" will try to execute the file as binary file and start it, if possible. This can end in security related issues. You can test it by creating a copy of cmd.exe calling it dummy.dat and start it using start dummy.dat

Upvotes: 2

jaimeandrescatano
jaimeandrescatano

Reputation: 166

20190907

OS: Win 10

I'm making an exe in c++, for some reason usting START make my program fail.

So, just use quotes:

"c:\folder\program.exe"

Upvotes: 0

Matt - MCTS
Matt - MCTS

Reputation: 291

In Windows 7+ the first quotations will be the title to the cmd window to open the program:

start "title" "C:\path\program.exe"

Formatting your command like the above will temporarily open a cmd window that goes away as fast as it comes up so you really never see it. It also allows you to open more than one program without waiting for the first one to close first.

Upvotes: 29

Ghorban ali arabi
Ghorban ali arabi

Reputation: 1

1-Open you folder that contains your application in the File Explorer. 2-Press SHIFT and Right Click in White Space. 3-Click on "Open command window here". 4-Run your application. (you can type some of the first characters of application name and press Up Arrow Key OR Down Arrow Key)

Upvotes: -1

Shersha Fn
Shersha Fn

Reputation: 1571

I got it working from qkzhu but instead of using MAX change it to MIN and window will close super fast.

@echo off
cd "C:\Program Files (x86)\MySQL\MySQL Server 5.6\bin"
:: Title not needed:
start /MIN  mysqld.exe
exit

Upvotes: 0

lscodex
lscodex

Reputation: 180

I think if you closed a program

taskkill /f /im "winamp.exe" 
//....(winamp.exe is example)...

end, so if you want to start a program that you can use

start "" /normal winamp.exe 

(/norma,/max/min are that process value cpu)

ALSO

start "filepath"enter image description here

if you want command line without openning an new window you write that

start /b "filepath"enter image description here

/B is 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.

Upvotes: 6

Fait Wise
Fait Wise

Reputation: 1

You can use the call command...

Type: call /?

Usage: call [drive:][path]filename [batch-parameters]

For example call "Example File/Input File/My Program.bat" [This is also capable with calling files that have a .exe, .cmd, .txt, etc.

NOTE: THIS COMMAND DOES NOT ALWAYS WORK!!!

Not all computers are capable to run this command, but if it does work than it is very useful, and you won't have to open a brand new window...

Upvotes: 0

Frank
Frank

Reputation: 696

Just remove the double quote, this works in Windows 7:

start C:\ProgramFiles\folderName\app.exe

If you want to maximize the window, try this:

start /MAX C:\ProgramFiles\folderName\app.exe


Your command START "filepath" will start a command prompt and change the command prompt title to filepath.

Try to run start /? in windows command prompt and you will get more info.

Upvotes: 4

whitfin
whitfin

Reputation: 4629

If you're doing it via CMD as you say, then you can just enter the command like so:

path\to\your.exe 

which will open it within the same window. For example in C++:

system("path\\to\\your.exe"); // Double backslash for escaping

will open your.exe in the current CMD window. Likewise to start with a new window, just go for:

system("start path\\to\\your.exe");

If you go for the first option, you would have to clear your screen unless you wanted to have the command to open your.exe on the screen still.

Upvotes: 0

John Watts
John Watts

Reputation: 8865

Add /B, as documented in the command-line help for start:

C:\>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.

Upvotes: 11

Related Questions