5

I want to hide the commands in the prompt that opened from a batch file. Example:

This is how it normally is:

Normal Prompt

This is how I want it to be:

Normal Prompt edited with Paint

It would be good as well if there was a way of output everything (except the commands) to a text file. I used the redirection operator (Time_Dif.bat > Time_Dif_Log.txt ) but it wrote the commands just like the prompt (as expected).

I searched and I found a lot of questions about how to hide the entire prompt from a batch or how to prevent the prompt from self closing in the end of the batch file but I want to hide only the commands.

The batch file:

set startTimeTwo=%time%
javac myPi_Two.java
java myPi_Two
set finishTimeTwo=%time%

set startTimeFour=%time%
javac myPi_Four.java
java myPi_Four
set finishTimeFour=%time%

set startTimeTen=%time%
javac myPi_Ten.java
java myPi_Ten
set finishTimeTen=%time%

echo myPi_Two: %startTimeTwo% %finishTimeTwo%
echo myPi_Four: %startTimeFour% %finishTimeFour%
echo myPi_Ten: %startTimeTen% %finishTimeTen%

pause

3 Answers 3

9

While searching for other problem in the use of redirection operator I discovered that just turning off the "echo" solved the problem.

Just open the prompt and write:

echo off

After that run your batch file from the same prompt while in the correct folder:

Time_Dif.bat

Or output the result to a text file:

Time_Dif.bat > Time_Dif_Log.txt

After that it will not show the commands in the prompt or in a external text file. Example:

Normal Prompt

EDITED (From answer of @Kyle A, comment of @JUICED_IT and TechNet):

It's possible to put @echo off in the beggining of the batch file so you can open direct from file explorer without commands being showed in the prompt. My final file:

@echo off

set startTimeTwo=%time%
javac myPi_Two.java
java myPi_Two
set finishTimeTwo=%time%

set startTimeFour=%time%
javac myPi_Four.java
java myPi_Four
set finishTimeFour=%time%

set startTimeTen=%time%
javac myPi_Ten.java
java myPi_Ten
set finishTimeTen=%time%

echo.
echo myPi_Two: %startTimeTwo% %finishTimeTwo%
echo myPi_Four: %startTimeFour% %finishTimeFour%
echo myPi_Ten: %startTimeTen% %finishTimeTen%

pause

I added echo. aswell to create an empty line, just for organize the output. Prompt after changes:

Prompt from batch file

2
  • Windows Command Line Batch Scripting 101... how to use the ECHO command. FYI... Kyle's answer is correct as well; just put @ECHO OFF as the first line in the batch file and it'll only ECHO the values you explicitly say ECHO some text so with this method, you will not need to type ECHO OFF in the command prompt before executing the script from that same prompt afterwards. May 20, 2016 at 3:11
  • @JUICED_IT Thank you, I didn't know about Windows Command Scripting, I'm in the middle of learning Java so didn't paid much attention to details... Sorry for asking something obvious, I'll be more careful in mine next question. May 20, 2016 at 10:22
3

Use the Echo command (@echo off).

1
  • I like your answer better but look at my comment on OP's answer for what you may want to add to your answer for further clarification to make it a more solid answer in my own personal opinion. May 20, 2016 at 3:13
0

Add cls after echo off befoure your code to prevent the command prompt from displaying something like: C:\Users\user>echo off

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .