How to start cmd from cmd

How to start cmd from cmd

start

Запускает отдельное окно командной строки для запуска указанной программы или команды.

Синтаксис

Параметры

. ]]Указывает запускаемую команду или программу.

Указывает параметры для передачи в команду или программу./?Отображение справки в командной строке.

Комментарии

Вы можете запускать неисполняемые файлы с помощью сопоставления файлов, вводя имя файла в виде команды.

При выполнении команды, содержащей строку CMD в качестве первого маркера без квалификатора расширения или пути, команда CMD заменяется значением переменной COMSPEC. Это не позволяет пользователям выбирать cmd из текущего каталога.

Если вы запускаете приложение с 32-битным графическим пользовательским интерфейсом (GUI), программа cmd не ждет завершения работы приложения, прежде чем вернуться в командную строку. Такое поведение не происходит при запуске приложения из командного скрипта.

Если выполнить команду, использующую первый токен, который не является командой, или путь к существующему файлу с расширением, Cmd.exe использует значение переменной среды ПАСЕКСТ, чтобы определить, какие расширения следует искать и в каком порядке. Значение по умолчанию для переменной ПАСЕКСТ:

Обратите внимание, что синтаксис аналогичен переменной PATH с точкой с запятой (;) Отделение каждого расширения.

начинает поиск указанного исполняемого файла и, если найден, исполняемый файл запустится независимо от текущего рабочего каталога. При поиске исполняемого файла, если нет совпадения с каким-либо расширением, запустите проверку, чтобы проверить, совпадает ли имя с именем каталога. Если это так, то Start открывает Explorer.exe по этому пути.

Примеры

Чтобы просмотреть раздел справки по командной строке в отдельном окне командной строки с развернутым окном, введите:

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:

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

How can I do this?

10 Answers 10

Trending sort

Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.

It falls back to sorting by highest score if no posts are trending.

Switch to Trending sort

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.

How to start cmd from cmd. Смотреть фото How to start cmd from cmd. Смотреть картинку How to start cmd from cmd. Картинка про How to start cmd from cmd. Фото How to start cmd from cmd

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 formatting of the command string becomes more complicated when using arguments with spaces. See the examples below. Note the 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»»

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.

How to start cmd from cmd. Смотреть фото How to start cmd from cmd. Смотреть картинку How to start cmd from cmd. Картинка про How to start cmd from cmd. Фото How to start cmd from cmd

This is not very easy.

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.

How to start cmd from cmd. Смотреть фото How to start cmd from cmd. Смотреть картинку How to start cmd from cmd. Картинка про How to start cmd from cmd. Фото How to start cmd from cmd

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

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.

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.

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:

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?

10 Answers 10

Trending sort

Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.

It falls back to sorting by highest score if no posts are trending.

Switch to Trending sort

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

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.

How to start cmd from cmd. Смотреть фото How to start cmd from cmd. Смотреть картинку How to start cmd from cmd. Картинка про How to start cmd from cmd. Фото How to start cmd from cmd

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

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

If you want to maximize the window, try this:

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

How to start cmd from cmd. Смотреть фото How to start cmd from cmd. Смотреть картинку How to start cmd from cmd. Картинка про How to start cmd from cmd. Фото How to start cmd from cmd

I think if you closed a program

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

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

start «filepath»How to start cmd from cmd. Смотреть фото How to start cmd from cmd. Смотреть картинку How to start cmd from cmd. Картинка про How to start cmd from cmd. Фото How to start cmd from cmd

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

start /b «filepath»How to start cmd from cmd. Смотреть фото How to start cmd from cmd. Смотреть картинку How to start cmd from cmd. Картинка про How to start cmd from cmd. Фото How to start cmd from cmd

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

How to start cmd from cmd. Смотреть фото How to start cmd from cmd. Смотреть картинку How to start cmd from cmd. Картинка про How to start cmd from cmd. Фото How to start cmd from cmd

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

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

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

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.

You can use the call command.

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.

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

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

So, just use quotes:

How to start cmd from cmd. Смотреть фото How to start cmd from cmd. Смотреть картинку How to start cmd from cmd. Картинка про How to start cmd from cmd. Фото How to start cmd from cmd

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:

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

Will bring up the calculator.

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

how to chain the START command in cmd?

My goal is to be able to chain START commands in a single cmd line.

Lets say I have a cmd window (lets call it starter). With a single line I want to start a new cmd window (lets call it cmd1) that will echo 1 and start another cmd window (lets call it cmd2) that will echo 2 and wait (with pause), after cmd1 called cmd2 (without waiting for it to finish) it will wait as well (with pause), after starter called cmd1 (without waiting for it to finish) it will close (or do nothing)

In the end I should end up with 2 cmd windows (cmd1 with «1» printed, cmd2 with 2 printed) and both are waiting for ENTER.

I wrote this cmd line in a bat file:

(the «title starter» is just for understanding which window is opened and should not be included in the final line)

with that cmd line, starter is the one that prints 2 and waits, and cmd1 just exits after calling cmd2.

The running scheme of that line:

I tried some other variations of this line with no success.

(important to note that I can open the 2 cmds (cmd1, cmd2) from the first cmd (starter) and the result of this will be the final result of my wanted running scheme, but it is important that cmd1 will be the one that creates cmd2)

So, does anyone know how may I achieve the running scheme that I want?

How to start cmd from cmd. Смотреть фото How to start cmd from cmd. Смотреть картинку How to start cmd from cmd. Картинка про How to start cmd from cmd. Фото How to start cmd from cmd

2 Answers 2

Trending sort

Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.

It falls back to sorting by highest score if no posts are trending.

Switch to Trending sort

I hope, I understood your requirements right.

The trick is proper escaping of & to pass it through the first pass of parsing to get then parsed with the second step.

I added titles to all windows.

Here is a script that will recursively START any arbitrary number of windows. Simply pass the count as the first and only argument to the script. If you don’t provide the count, then it will only open 1 window.

RecursiveStart.bat

For example, to start 5 windows, simply use:

However, if all you want to do is open N number of windows and execute some commands in each, and each window is entirely independent of the other (don’t care who started it), then it is much simpler to iterate the START command N times in your parent script.

start

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

Syntax

Parameters

ParameterDescription
Specifies the title to display in the Command Prompt window title bar.
/d

Specifies the startup directory./iPasses the Cmd.exe startup environment to the new Command Prompt window. If /i is not specified, the current environment is used.Specifies to minimize (/min) or maximize (/max) the new Command Prompt window.Starts 16-bit programs in a separate memory space (/separate) or shared memory space (/shared). These options are not supported on 64-bit platforms.Starts an application in the specified priority class./nodeSpecifies the preferred Non-Uniform Memory Architecture (NUMA) node as a decimal integer./affinityApplies the specified processor affinity mask (expressed as a hexadecimal number) to the new application./waitStarts an application and waits for it to end./bStarts an application without opening a new Command Prompt window. CTRL+C handling is ignored unless the application enables CTRL+C processing. Use CTRL+BREAK to interrupt the application.[ [

. ]]Specifies the command or program to start.

Specifies parameters to pass to either the command or the program./?Displays help at the command prompt.

Remarks

You can run non-executable files through their file association by typing the name of the file as a command.

If you run a command that contains the string CMD as the first token without an extension or path qualifier, CMD is replaced with the value of the COMSPEC variable. This prevents users from picking up cmd from the current directory.

If you run a 32-bit graphical user interface (GUI) application, cmd does not wait for the application to quit before returning to the command prompt. This behavior does not occur if you run the application from a command script.

If you run a command that uses a first token that is not a command or the file path to an existing file with an extension, Cmd.exe uses the value of the PATHEXT environment variable to determine which extensions to look for and in what order. The default value for the PATHEXT variable is:

Note that the syntax is the same as the PATH variable, with semicolons (;) separating each extension.

start searches for a specified executable file, and if found the executable will launch regardless of the current working directory. When searching for an executable file, if there is no match on any extension, start checks to see if the name matches a directory name. If it does, start opens Explorer.exe on that path.

Examples

To start the Myapp program at the command prompt and retain use of the current Command Prompt window, type:

To view the start command-line help topic in a separate maximized Command Prompt window, type:

Источники информации:

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *