Create cmd command with parameters in batch [duplicate] - batch-file

This question already has answers here:
How can I pass arguments to a batch file?
(20 answers)
Closed 6 years ago.
I want to create a cmd command by writing a batchfile and put it into "system32" to call it in the cmd console by its name. Is there a way to expect parameters in the batch file:
Write in cmd:
fake-command Test
And then work with the string "Test" in the batch file?

Use %1 to access the first argument, %2 for the second, etc.

Related

How to paste in the command line (not using shortcuts/mouse)? [duplicate]

This question already has answers here:
How can you get the clipboard contents with a Windows command?
(14 answers)
Access clipboard in Windows batch file
(11 answers)
Closed 2 years ago.
I am working on a batch script that runs .exe files in a given folder. It should do something like this:
SET /P _inputname= Please enter app folder path:
cd %_inputname%
dir /s /b *.exe | clip
"paste-from-clipboard"
However, for my last line, I haven't found a way to paste from clipboard without using a mouse/keyboard shortcut. I would greatly appreciate it if anyone has a solution.
To copy & paste within windows command line you can use:
https://github.com/kpym/windows-paste
It's the successor of the once famous paste.exe.
See also How can you get the clipboard contents with a Windows command?

How do I make a self locating batch file [duplicate]

This question already has answers here:
Get current batchfile directory
(4 answers)
Closed 3 years ago.
So basicly I want to make a batch file that can execute other files, while learing its own location on execution.
It should then use it own path as a reference to the other files.
How should I go about coding that or are there any guides for exactly that?
Thanks in advance!
The batch file name as entered via command line is stored in %0. Using file expander to get other parts. You can put the following code into a batch file and try it out:
REM print batch filename as user entered
echo %0
REM print full file name: d - drive, p - path, f - filename
echo %~dpf0
REM print path only
echo %~dp0
The current directory is stored in %CD%, in case you need it.

How to echo something to a .txt file even if it's executable as a program BATCH [duplicate]

This question already has answers here:
using batch echo with special characters
(8 answers)
Closed 4 years ago.
I have a BATCH script that will create a text file that will later be executed by another program based on user input. I want to be able to echo Label>start to a text file. Unfortunately, CMD reads it as a command (because of the > character) and does not echo properly. If I use quotation marks they echo to the .txt file
"Level>start"
and so it cannot be executed. I really need some help with this.
echo Level^>start
seems to work.

How to run Diskpart in batch file? [duplicate]

This question already has answers here:
How do I minimize the command prompt from my bat file
(14 answers)
Closed 6 years ago.
I have Created Text file where it contains dispart commands and I run it from
The Batch File using the code below:
#echo off
Diskpart.exe /s D:\script.txt
Hopefully, That's works fine but there is something I don't want it to happen anymore and that was when Dispart.exe opened.It is openning maximized.
So how to make it openning minimized?
Use this command in your .bat file:
start /min diskpart
Hope this helps. Good luck!

What is the definition behind `%0 | %0`? [duplicate]

This question already exists:
Batch fork bomb? [duplicate]
Closed 8 years ago.
Please help me to find the definition behind this code:
%0 | %0
If we save this code in a .bat file and run it our CPU & MEMORY usage will go to 100%.
%n is the n-th argument when calling a program or batch file. %0 will be the first parameter or the file name of the executatble/script. Hence %0 will run it's own file, and the copy will again run it's own. This continues forever and cannot exit

Resources