How can i prevent my batch file from showing Path? - batch-file

[How can i prevent it from showing C:/Users/[Username]/Desktop/ ? Link
My code:
#Echo off
title Menu
color A
echo You can do anything,but please don't delete system32!
echo color (1-11) title (name)
echo If you type CLS you can hide the hints!
echo For Game and Program codes type in: Codes!
cmd /k

Use prompt, for example:
cmd /k prompt $$ changes the prompt to $
cmd /k prompt $T$G$S changes the prompt to 17:29:12,44> (with space at the end)
See more formatting codes by running prompt /? in the Command Prompt console.

Related

How to make a batch file that lets you use cmd after?

what I'm essentially trying to do is make a batch file (or shortcut if possible) to change to a directory, echo a message, and then let you use the cmd window as if you had opened it up normally after.
Example:
The batch file/shortcut opens a cmd prompt in C:\test-folder\
Echos "This is your message"
Awaits user input for commands
I've tried the following command:
start cmd /k cd /d C:\test-folder\
echo test
The folder change will work without the echo line, but if I include the echo line, it will not work at all.
Is there any way to do what I'm trying to accomplish here?
the order of the switches matters. See start /? and cmd /? for details.
start "My window" /d "d:\" cmd /k "echo Hello&echo use me"
"My window" belongs to start and gives the new window a title.
/d "c:\test-Folder\" also belongs to start and gives the startdirectory
cmd is the command to start
/k belongs to cmd and has to be cmd's (only or) last Switch
"echo Hello&echo use me" is the commandline to execute.
Your problem is the echo test is run in the parent window that issues the START command. You want the ECHO to occur in the window that START launches.
One option is to append the ECHO command to the end of the START command, remembering to escape the & so that it is included as part of the CMD /K option.
start cmd /k cd /d C:\test-folder\ ^& echo test
Or you could put quotes around the entire /K option (CMD will remove the quotes before executing the string):
start cmd /k "cd /d C:\test-folder\ & echo test"
Or you could use Stephan's suggestion to let START set your active directory, so that your CMD /K option only needs to ECHO the message.
start /d "C:\test-folder" cmd /k echo test
Or you can create a shortcut and edit the properties such that
"Target" = C:\Windows\System32\cmd.exe /k echo test
and
"Start in" = c:\test-folder
If you create a batch file that ends with cmd /k, it will run the commands before cmd /k and then leave you in a command prompt. This is useful if you're performing enough work that makes a one-liner shortcut hard to write.
To get the behaviour you described, you can create a file called "open_test_folder.cmd" with the following:
#echo off
cd C:\test-folder
echo This is your message
cmd /k

Open command window via batch file when cmd.exe is blocked

cmd.exe is blocked at school. However batch files runs normally and sometimes it's very annoying to type the command in the batch file, write pause>nul and run the batch file to execute a command. Is there anyway to input commands from the user and execute them as cmd.exe does?
#echo off
:Loop
echo %cd%^>
set /p cmd=SkYWAGz Enter Command to Run (Press Ctrl + C to exit)
%cmd%
Goto Loop
Your very own command processor
I found the solution, the code in the batch file would be start
This works for me:
#echo off
break off
title Command Prompt
cls
:cmd
set /p cmd="%cd%>"
%cmd%
echo.
goto cmd

Keep CMD open after BAT file executes

I have a bat file like this:
ipconfig
That will print out the IP info to the screen, but before the user can read that info CMD closes itself.
I believe that CMD assumes the script has finished, so it closes.
How do I keep CMD open after the script is finished?
Put pause at the end of your .BAT file.
Depending on how you are running the command, you can put /k after cmd to keep the window open.
cmd /k my_script.bat
Simply adding cmd /k to the end of your batch file will work too. Credit to Luigi D'Amico who posted about this in the comments below.
Just add #pause at the end.
Example:
#echo off
ipconfig
#pause
Or you can also use:
cmd /k ipconfig
When the .bat file is started not from within the command line (e.g. double-clicking).
echo The echoed text
#pause
echo The echoed text
pause
echo The echoed text
cmd /k
echo The echoed text & pause
Adding pause in (Windows 7) to the end did not work for me
but adding the cmd /k in front of my command did work.
Example :
cmd /k gradlew cleanEclipse
start cmd /k did the magic for me. I actually used it for preparing cordova phonegap app it runs the command, shows the result and waits for the user to close it. Below is the simple example
start cmd /k echo Hello, World!
What I did use in my case
start cmd /k cordova prepare
Update
You could even have a title for this by using
start "My Title" echo Hello, World!
If you are starting the script within the command line, then add exit /b to keep CMD opened
In Windows add '& Pause' to the end of your command in the file.
I was also confused as to why we're adding a cmd at the beginning and I was wondering if I had to open the command prompt first.
What you need to do is type the full command along with cmd /k. For example assume your batch file name is "my_command.bat" which runs the command javac my_code.java then the code in your batch file should be:
cmd /k javac my_code.java
So basically there is no need to open command prompt at the current folder and type the above command but you can save this code directly in your batch file and execute it directly.
javac -d C:\xxx\lib\ -classpath C:\xxx\lib\ *.java
cmd cd C:\xxx\yourbat.bat
the second command make your cmd window not be closed.
The important thing is you still able to input new command
As a sidenote this also works when running a command directly from the search bar in windows.
e.g. directly running ipconfig will directly close the cmd window after the command has exited.
Using cmd \k <command> won't - which was what i was trying to do when i found this answer.
It has the added advantage of always recognizing the command you're trying to run. E.g. running echo hello world from the searchbar won't work because that is not a command, however cmd \k echo hello world works just fine.

Start a CMD, then echo off of it, then clear the screen

Here are the steps I need, I am using a batch script
Open a cmd with path set to the desktop
Then set it's echo off
Then clear the screen
Then wait for me to type commands
So I can enter the commands directly without a long line blocking the view
Code I tried so far
#echo off
cd "C:\Documents and Settings\Administrator\Desktop"
cls
cmd
#echo off
cls
But when I run this I get a typical CMD window, where I have to type "echo off" & "cls" again to get a clean window.
The output I get is
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\Documents and Settings\Administrator\Desktop>
The output I want is simple
Imagine a blinking underscore
_
Thank you.
Try this line:
start /D "C:\Documents and Settings\Administrator\Desktop" cmd /k "prompt $"
/D <path> will set your working directory
Prompt $ will set your prompt to "nothing", only the blinking cursor will display
The output I want is simple
_
You can achive this with the prompt command, e.g. prompt $S or prompt $g
Here's an example batch file that would open up a new cmd window with an empty prompt:
#echo Off
start cmd /k "prompt $g"
create a VBS file using notepad
add this lines
Set cmd = CreateObject("WScript.Shell")
cmd.run"cmd"
WScript.Sleep 200
cmd.Sendkeys"echo off{Enter}"
WScript.Sleep 200
cmd.Sendkeys"cls{Enter}"
WScript.Sleep 200
This command can be very problematic (cmd /c "echo off | clip")
USE WITHOUT QUOTES:
cmd /c echo off | clip
goto off
(Save as .bat)
No more problems !!!
I just used
cls
echo off
cls
cmd|echo off
cls
in a batch file. Works for me

How to set the settings of a command prompt using the batch file?

prompt $
cls
cmd
color 87
This is my batch file. It opens the command prompt but with its default settings.How can i change the color and prompt of a command prompt before i open it in a batch file? How do i make it? Thank you in advance
cmd /? provides you with some useful information.
This should do what you want:
cmd /K "color 87"

Resources