Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use batch commands call, start, goto

2025-03-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the knowledge of "how to use batch commands call, start, goto". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

1. Call command

CALL calls one batch program from another without terminating the parent batch program. There are two main uses of call command, one is to call other batch programs (* .bat, * .bat), the most commonly used are * .exe files and * .bat files, and the other is CALL: label arguments

C:\ Users\ Administrator > help call calls another batch program from the batch program. CALL [drive:] [path] filename [batch-parameters] batch-parameters specifies the command line information required by the batch program. If the command extension is enabled, the CALL changes as follows: the CALL command now accepts the volume label as the target of the CALL. The syntax is: CALL:label arguments A new batch file context is created by the specified parameter, and the control is passed to the statement after the volume label is specified. You must "exit" twice by reaching the last two batch script files. When you first read the end of the file, the control goes back to the end of the CALL statement. The batch script is exited the second time. Type GOTO /? and see the description of the GOTO: EOF extension, which allows you to return from a batch script. In addition, the parameters of the batch script reference (% 0,% 1, etc.) have been changed as follows:% * in the batch script indicates all parameters (such as% 1% 2% 3% 4% 5.) The substitution of the batch parameter (% n) has been enhanced. You can use the following syntax:% ~ 1-remove quotation marks (") Extend% 1 ~ F1-extend% 1 to a fully qualified pathname% ~ D1-extend% 1 to only one drive letter% ~ p1-extend% 1 to only one path% ~ N1-extend% 1 to only one filename% ~ x1 -extend% 1 to only one file extension% ~ S1-the path of the extension contains only the short name% ~ A1-extend% 1 to the file attribute% ~ T1-extend% 1 to the date / time of the file% ~ Z1-extend% 1 to the size of the file % ~ $PATH:1-find the directory listed in the PATH environment variable And extend% 1 to the first fully qualified name found. If the environment variable name is not defined, or if the file is not found This modifier extends to empty strings and modifiers can be combined to achieve multiple results:% ~ dp1-extend% 1 only to drive letter and path% ~ nx1-extend% 1 only to file name and extension% ~ dp$PATH:1-look for% 1 in directories listed in the PATH environment variable And expand to the drive letter and path of the first file found. % ~ ftza1-extends% 1 to output lines like DIR. In the above example,% 1 and PATH can be replaced by other valid values. % ~ the syntax is terminated by a valid parameter number. The% ~ modifier cannot invoke the batch with% * using 1.1

Command format CALL [drive:] [path] filename [batch-parameters]

Create a file test.bat call file call.bat

@ echo offset a = environment variable call call.bat hi hellopauseexit / b 0::call.batecho cho% 2echo% a%

The running results are as follows:

Note:

1. Use the command @ echo off,call.bat only in test.bat and there is no echo command

2. Set the environment variable in test.bat, which can be used in call.bat

1.2 call target label

Note:

1. ":" is required when calling the tag.

2. Continue to process the following commands after calling the tag

Example one

@ echo offcall: interCall hi helloecho next step pauseexit / b 0: intercallecho cho% 2

Running result:

Example two

@ echo offcall: interCallecho next step: intercallecho hiecho helloPAUSEexit / b 0

2. The difference between calling call and not using call

1. Using call does not terminate the parent process. After calling the batch without call, the parent process is terminated and subsequent commands are no longer processed.

Rem test.bat@echo offset a = environment variable call call.bat hi helloecho next pauseexit / b 0rem call.batecho cho% 2echo% a%pause

2.2 the running result of removing call from call call.bat hi hello is as follows:

3. Goto command

The help documentation is as follows

C:\ Users\ Administrator > help goto directs the cmd.exe to the labeled line in the batch program. GOTO label label specifies the text string used as a label in the batch program. The label must be on a separate line and start with a colon. If the command extension is enabled, the GOTO changes as follows: the GOTO command now accepts the target tag: EOF, which transfers control to the end of the current batch script file. It is an easy way to exit the batch script file without definition. For an extended description of the CALL commands that make this feature useful, type CALL /?.

3.1 do not need ":" after goto, add label directly

3.2 after goto skips to the specified label, skipped command statements are not processed

@ echo offgoto interCallecho next step: intercallecho hiecho helloPAUSEexit / b 0

Run result: the statement "echo next" is not processed

4. Start is similar to creating a thread C:\ Users\ Administrator > help start to start a separate window to run the specified program or command. START ["title"] [/ D path] [/ I] [/ MIN] [/ MAX] [/ SEPARATE | / SHARED] [/ LOW | / NORMAL | / HIGH | / REALTIME | / ABOVENORMAL | / BELOWNORMAL] [/ NODE] [/ AFFINITY] [/ WAIT] [/ B] [command/program] [parameters] "title" displays the title in the window title bar. Path startup directory. B starts the application but does not create a new window. The application has ignored ^ C processing. Unless the application enables ^ C processing, ^ Break is the only way to interrupt the application. I the new environment will be the original environment passed to cmd.exe, not the current environment. MIN launches the window in a minimized manner. MAX launches the window in a maximized manner. SEPARATE starts a 16-bit Windows program in a separate memory space. SHARED starts a 16-bit Windows program in a shared memory space. LOW starts the application in the IDLE priority class. NORMAL starts the application in the NORMAL priority class. HIGH starts the application in the HIGH priority class. REALTIME starts the application in the REALTIME priority class. ABOVENORMAL starts the application in the ABOVENORMAL priority class. BELOWNORMAL starts the application in the BELOWNORMAL priority class. NODE specifies the preferred inconsistent memory structure (NUMA) node as a decimal integer. AFFINITY specifies the processor association mask as a hexadecimal number. Processes are restricted to running on these processors. When / AFFINITY and / NODE are combined, the association mask is interpreted differently. Specify the associative mask, just as the processor mask of the NUMA node is moved correctly to the zero starting position. Processes are restricted to those general-purpose processors between the specified association mask and the NUMA node. If there is no general-purpose processor, the process is restricted to running on the specified NUMA node. WAIT starts the application and waits for it to terminate. Command/program if it is an internal cmd command or batch file, the command processor runs using the / K switch of cmd.exe. This means that the window will still exist after running the command. If it is not an internal cmd command or batch file, it is a program and will run as a windowing or console application. Parameters these are the parameters passed to command/program. Note: the SEPARATE and SHARED options are not supported on 64-bit platforms. By specifying / NODE, you can create a process in a way that leverages the memory area in the NUMA system. For example, you can create two processes that communicate with each other entirely through shared memory to share the same preferred NUMA node, minimizing memory latency. If possible, they allocate memory from the same NUMA node and run freely on processors other than the specified node. Startup / NODE 1 application1.exe startup / NODE 1 application2.exe these two processes can be further limited to running on a specified processor within the same NUMA node. In the following example, application1 runs on two low-order processors of a node, while application2 runs on the next two processors of that node. This example assumes that the specified node has at least four logical processors. Note that the node number can be changed to any valid node number for this computer without changing the associated mask. Start / NODE 1 / AFFINITY 0x3 application1.exe start / NODE 1 / AFFINITY 0xc application2.exe if the command extension is enabled, the external command invocation through the command line or START command will be changed as follows: type the file name as a command, and non-executable files can be invoked through file association. (for example, WORD.DOC invokes the application associated with the .DOC file extension.) For information about how to create these associations from within the command script, see the ASSOC and FTYPE commands. When the executing application is a 32-bit GUI application, CMD.EXE returns a command prompt without waiting for the application to terminate. If executed within a command script, the new behavior does not occur. If the first symbol on the command line executed is the string "CMD" without an extension or path modifier, "CMD" is replaced by the numeric value of the COMSPEC variable. This prevents CMD.EXE from being extracted from the current directory. If the first symbol of the command line executed does not have an extension, CMD.EXE uses the value of the PATHEXT environment variable to determine which extensions to look for in what order. The default value for the PATHEXT variable is: .com; .exe; .bat; .CMD. Note that the syntax is the same as for the PATH variable, with semicolons separating different elements. When looking for an executable file, if there is no matching extension, see if the name matches the directory name. If so, START calls Explorer on that path. If executed from the command line, it is equivalent to CD / D on that path.

4.1 can be compared with paragraph 2, "the difference between calling call and not using call" code

@ echo offset a = environment variable start call.bat hi helloecho next step pauseexit / b 0

The call.bat content is as follows

Rem call.batecho cho 2echo a%pause

Running result

This is the end of the content of "how to use batch commands call, start, goto". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report