当前位置:网站首页>[batch dos-cmd command - summary and summary] - application startup and call, service and process operation commands (start, call, and)
[batch dos-cmd command - summary and summary] - application startup and call, service and process operation commands (start, call, and)
2022-06-25 07:31:00 【dssgresadfsrgre】
One 、 Program startup command ——start
start Command is usually used to open a file ( It is usually an executable program ) Or folder .
First use start /? Command for general help information .

(1) Open a folder .start dir, This dir It can be the root directory of the disk , It can also be a subdirectory on the disk . If not min or max Parameters , It will be maximized by default ( Open at the front desk ).
If you want to open e Packing list , Carry out orders 【start e:】.

If you want to open e A folder under the root directory ( for example adobe), Carry out orders 【start e:\adobe】

(2) Open a file . start path, This path It can be a document type txt、doc、excel file , It can also be multimedia mp3、mp4 file , It can also be executable exe、bat file .
Try opening it exe file ,【start D:\ Summary of green installation free small software \PdgCntEditor_PDF Directory editor \PdgCntEditor.exe】.
Successfully opened .

(3) Whether it's opening a file , Or open the folder , Pay attention to the problem of spaces .
What do you mean ? What do you mean by paying attention to blank space ?
cmd Spaces are often used to distinguish between different parameters in the window , If you use a space, it often means that the next parameter is after the space or the value of the parameter before the space is given .
For example, the path of cool dog music is 【D:\Program Files (x86)\KuGou\KGMusic\KuGou.exe】, Then we execute the order 【start D:\Program Files (x86)\KuGou\KGMusic\KuGou.exe】, You'll find something wrong . Prompt file not found ( clip )【D:\Program】, It's easy to know cmd The program separates the path string before and after the space , How can we solve this problem ?

The solution is simple , Which level directory has a space in its name , Just put double quotation marks there . Carry out orders 【start D:\"Program Files (x86)"\KuGou\KGMusic\KuGou.exe】.

Note that the command is not executed 【start "D:\Program Files (x86)\KuGou\KGMusic\KuGou.exe"】 , I don't know why , Visually reflect , Will reopen a cmd window , Working directory unchanged .
If there are multiple spaces on the full path , It is obviously troublesome to add double quotation marks to each level .
In fact, we have another way .
Suppose you want to open a folder 【D:\BaiduNetdiskDownload\test1 2 3\test 3 4 5】, Carry out orders 【start "" "D:\BaiduNetdiskDownload\test1 2 3\test 3 4 5"】( Fill in the first double quotation mark ).

(4) If you do not want the window to appear on the screen immediately after executing the command , That is, you want to open it in the background , It can be used /min Parameters .
For example, open a exe Program , Carry out orders 【start /min D:\ Summary of green installation free small software \PdgCntEditor_PDF Directory editor \PdgCntEditor.exe】

Sure enough, it was opened in the backstage .
But I still found some programs , Even if you add /min Parameters ,
Can't open in the background , Like cool dog music .
Two 、 Program call command ——call
Call The purpose of the command is to call what has been written bat file , Suppose it is called bat File name is 【demo.bat】, Actively invoked bat The file name is 【main.bat】, So in main.bat Call in demo.bat It needs to be used call command .
similar C Function declaration in language , Function defined in demo.bat In the middle of , The function is declared in the main program file main.bat In the middle of .
Print first call Command help information .

Let's see how to use it call This command .
Create a new one demo.bat file , The code inside is .
@echo off
echo Now start executing the subroutine
echo You can count to 10 Do you ?
echo I can't help it ! 1,2,3,4,5,6,7,8,9,10
echo That's great
echo I wish you happiness
echo See the ghost
echo Why didn't you do anything later
echo See the ghost
echo Go on ?Let's create another one main.bat file , The code inside is .
chcp 65001
@echo off
echo Hey, Lao tie has got it ! The main program starts to run ...
echo Can you count ?
echo I'm not going to , But my son will , You ask him .
call D:\D-desktop\demo.bat
echo The main program is over , Have a good rest .
pauseVisible direct use 【call path】 You can successfully call .
But I still found some problems during the experiment .
The first question is : Suppose the last line of the subroutine file has pause, Will bring you closer pause The end of a period in a few lines of 、 Or the line at the end of the question mark should be treated as an order , It turns out to be wrong .
For example demo.bat File modification , and main.bat The document remains the same .
@echo off
echo Now start executing the subroutine
echo You can count to 10 Do you ?
echo I can't help it ! 1,2,3,4,5,6,7,8,9,10
echo That's great
echo I wish you happiness .
echo See the ghost .
echo Why didn't you do anything later .
echo See the ghost .
echo Go on ?
pauseAfter execution pause Before 4 There are problems in all the lines .

The second question is : Suppose I remove the last line of the subroutine file pause, Then, the last few lines of commands will fail .
Same will demo.bat The document is modified , then main.bat remain unchanged .
@echo off
echo Now start executing the subroutine
echo You can count to 10 Do you ?
echo I can't help it !1,2,3,4,5,6,7,8,9,10
echo That's great
echo I wish you happiness
echo See the ghost
echo Why didn't you do anything later
echo See the ghost
echo Go on The execution result is shown in the figure below , Last 4 OK, and the whole army was destroyed . Don't think it's just the end 4 That's why things go wrong , You can try it yourself , A lot of bug, Therefore, it is recommended to use this function with caution , You can put the code in the main program .

3、 ... and 、 process / Service operation ——tasklist、net
3.1 Process management
- Displays the currently running process :
tasklist - Run a program or command :
start The program name - The end of the process , By name :
taskkill /im notepad.exe( Close Notepad ) - The end of the process , Press PID:
taskkill /pid 1234( close PID by 1234 The process of )
3.2 Service management
- Displays the currently running services :
net start - Start the specified service :
net start service name - Stop the specified service :
net stop service name
边栏推荐
- Cocos learning diary 3 - API acquisition nodes and components
- What common APIs are involved in thread state changes
- Common functions of OrCAD schematic
- lotus windowPoSt 手动触发时空证明计算
- 313. Binary sum
- LabVIEW generate application (exe) and installer
- [tool sharing] a software that pays equal attention to appearance and skills
- 1W字|40 图|硬核 ES 实战
- [introduction to UVM== > episode_9] ~ register model, integration of register model, general methods of register model, application scenarios of register model
- Lotus windowsost manually triggers space-time proof calculation
猜你喜欢

我与CSDN的一年时光及大学经验分享

Streamnational platform version 1.5 is released, integrating istio and supporting openshift deployment

In depth analysis of Apache bookkeeper series: Part 3 - reading principle

【xxl-job】池塘水绿风微暖,记得玉真初见面

稳压二极管的原理,它有什么作用?

Weimeisi new energy rushes to the scientific innovation board: the annual revenue is 1.7 billion, and the book value of accounts receivable is nearly 400million

Classic paper in the field of character recognition: aster

【UVM入門 ===> Episode_9 】~ 寄存器模型、寄存器模型的集成、寄存器模型的常規方法、寄存器模型的應用場景

【LeetCode】two num·两数之和

Several schemes of traffic exposure in kubernetes cluster
随机推荐
Weimeisi new energy rushes to the scientific innovation board: the annual revenue is 1.7 billion, and the book value of accounts receivable is nearly 400million
ES 终于可以搜到”悟空哥“了!
1W words | 40 pictures | hard core es actual combat
How do I know if mysqlnd is an active driver- How to know if MySQLnd is the active driver?
【LeetCode】two num·两数之和
The principle of Zener diode, what is its function?
I have used it for six years!
SQL query, if value is null then return 1 - SQL query, if value is null then return 1
[Introduction aux uvm== > Episode 9] ~ modèle de registre, intégration du modèle de registre, méthode conventionnelle du modèle de registre, scénario d'application du modèle de registre
太美的承诺因为太年轻
【xxl-job】池塘水绿风微暖,记得玉真初见面
深入解析 Apache BookKeeper 系列:第三篇——读取原理
Event registration Apache pulsar x kubesphere online meetup hot registration
基於 KubeSphere 的分級管理實踐
Flexbox on ie11: stretching images for no reason- Flexbox on IE11: image stretched for no reason?
48 pictures | teach you the performance monitoring, pressure testing and tuning of microservices by hand
Debug through yalc before releasing NPM package
MCU IO explanation (pull-up pull-down quasi bidirectional input / output push-pull open drain)
Analysis on the trend of the number of national cinemas, film viewers and average ticket prices in 2021 [figure]
我与CSDN的一年时光及大学经验分享