Software-OK
≡... News | ... Home | ... FAQ | Impressum | Contact | Listed at | Thank you |

  
HOME ► Faq ► FAQ - Windows cmd.exe Command-Prompt ► ««« »»»

Command line arguments in the command prompt with examples!


For parameters that can be passed when the batch file is called and other variables via the set on Windows 11, 10, ... and MS Server OS!



Contents:

1.) ... command line arguments in the command prompt!
2.) ... use variables in the command prompt cmd.exe!
3.) ... Local and global variables, understand the difference!





Everyone who likes to use variables and work with arguments is familiar with these possibilities and likes to benefit from the advantages under all operating systems and not only under Microsoft Windows 11/10 and MS Server OS!  


1.) Command line arguments in the command prompt!

Batch Scripts / Command Prompts support command line arguments where arguments can be passed to the batch file when invoked. The arguments can be called from the batch files via the variables %1,%2,%3, ... etc.



@echo off 
echo %1 
echo %2 
echo %3
pause


If the above batch script is saved in a file called test.bat and execute the batch, for example via a Windows shortcut and use arguments! 
 

Test.bat one two three



When the batch file is executed, these values ​​can be output 

( ... see Image-1 Point 1 to 3)

(Image-1) Command line arguments in the command prompt example
Command line arguments in the command prompt example

-
▲ Back to the top ▲




2.) Use variables in the command prompt cmd.exe!

The other way variables can be initialized is with the 'set' command. The following is the syntax of the set command .

EXAMPLE 1:


@echo off 
set message=Hello how are you
echo %message%


In the example above, a variable called  message is  defined and given the value "Hello how are you".
 
Note that the variable must be enclosed in % signs in order to display the value of the variable.


EXAMPLE 2: Working with Numerical Values

In the batch script it is also possible to define a variable that contains a numerical value. This can be done with the switch / A.
 
The following code shows an easy way how numeric values ​​can be used with.


@echo off 
SET /A a = 5 
SET /A b = 10 
SET /A c = %a% + %b% 
echo %c%
pause
 


(Image-2) Command line arguments Use numerical values!
Command line arguments Use numeric values!

-
▲ Back to the top ▲




3.) Local and global variables, understand the difference!


In every programming language there is an option to mark variables with a range, that is, the section of code that can be accessed. Typically, variables with a global scope can be accessed anywhere from a program, while variables with a local scope have a defined limit at which they can be accessed.

Example of global and local variables




@echo off
set globalvar = 5
SETLOCAL
set var = 13145
set / A var =% var% + 5
echo% var%
echo% globalvar%
ENDLOCAL
pause

(Image-3) Local and global variables!
Local and global variables!

-
▲ Back to the top ▲




FAQ 103: Updated on: 7 August 2021 18:56 Windows
Windows-Console

Connection to remote desktop service via command prompt!


It is easy to start a connection to the Remote Desktop Service via the command prompt with arguments on Windows 11, 10, and MS Server OS   Contents:
Windows-Console

Waiting for keyboard input Command prompt Script?


Often you want to stop the script in the batch file and wait for the user to press Enter, or variables to process on Windows 11, 10, and MS Server OS
Windows-Console

Files that are younger than the date can be deleted via the command line!


It is quite easy to delete files that are younger than a certain date via the command line under Windows 11, 10, and MS Server OS Everyone probably
Windows-Console

Delete all files except the most recent via command line, script or CMD.EXE?


It is easy to delete all files except the most recent via command line, script or CMD.EXE for Windows 11, 10, and MS Server The most popular script
Windows-Console

Ability to batch rename files in lower and upper case?


It is easy to rename files in batches using a script or command prompt in lower and / or upper case letters on Windows 11, 10, and MS Server OS Everyone
Windows-Console

Serial number of the hard disk under Windows 11, 10, ... via command prompt!


It is quite easy to find out the serial number of your hard disk under Windows 11, 10, or MS Server 2022, at a command prompt There are free hard
Windows-Console

Find out the PC serial number and manufacturer via command prompt?


Using the command prompt, it is easy to find out the PC serial number and manufacturer under Windows 11, 10, and MS Server OS Everyone has ► read out

»»

  My question is not there in the FAQ
Asked questions on this answer:
Keywords: windows, 11, 10, console, command, line, arguments, prompt, examples, parameters, passed, batch, file, variables, contents, Questions, Answers, Software




    

  + Freeware
  + Order on the PC
  + File management
  + Automation
  + Office Tools
  + PC testing tools
  + Decoration and fun
  + Desktop-Clocks

  + SoftwareOK Pages
  + Micro Staff
  + Freeware-1
  + Freeware-2
  + Freeware-3
  + FAQ
  + Downloads

  + Top
  + Desktop-OK
  + The Quad Explorer
  + Don't Sleep
  + Win-Scan-2-PDF
  + Quick-Text-Past
  + Print Folder Tree
  + Find Same Images
  + Experience-Index-OK
  + Font-View-OK


  + Freeware
  + DesktopClock3D
  + PointerStick
  + DesktopImages3D
  + WinPing
  + GetPixelColor
  + StressMyPC
  + DesktopSnowOK
  + Delete.On.Reboot
  + IsMyTouchScreenOK
  + PAD-s


Home | Thanks | Contact | Link me | FAQ | Windows 2021 | Windows 10 | English-AV | Impressum | Translate | PayPal | PAD-s

 © 2023 by Nenad Hrg softwareok.de • softwareok.com • softwareok.com • softwareok.eu
0.077


► How do I uninstall and install Cortana on Windows 11? ◄

► Percentage usage of every file and folder on Windows (11, 10, 8.1, 7)! ◄

► Group the tiles in the Windows 10 Start menu! ◄

This website uses cookies to ensure you get the best experience on our website more Infos & Privacy Policy
....