2

I want to make file.bat that should run my jar only when user press enter. Bat must run and does't execute anything without user press enter. In cmd should be printed:

java -jar crawler-1.0.jar

A part from that user could change this.text

How can I do this?

Oleg Baranenko
  • 398
  • 2
  • 16

4 Answers4

7

Excuse me. I think that the real goal of this question is: "How to prefill the cmd.exe command-line input with an editable string", so the user may just press Enter key to execute the prefilled input, or edit it in any desired way. I copied the method below from this post:

@if (@CodeSection == @Batch) @then

@echo off
rem Enter the prefill value in the keyboard buffer
CScript //nologo //E:JScript "%~F0" "java -jar crawler-1.0.jar"
goto :EOF

@end

WScript.CreateObject("WScript.Shell").SendKeys(WScript.Arguments(0));
Community
  • 1
  • 1
Aacini
  • 65,180
  • 12
  • 72
  • 108
  • It's unclear what this question is asking, exactly, but this sounds like it's probably what the OP wants. – mttdbrd Apr 27 '15 at 05:03
2

Try this:

@echo off
Echo java -jar crawler-1.0.jar
set /p =
java -jar crawler-1.0.jar
Echo.
pause

That way, the program will start only if the user hits enter (and not any other key). Also, the window should remain to show the output from the program.

Monacraft
  • 6,510
  • 2
  • 17
  • 29
  • It close after show output and press enter, It must works until user close window. Maybe, I bad explained what I need :( I need the same as cmd work, but with already put text in command line and user could change this text – Oleg Baranenko Apr 25 '15 at 19:44
0

You can always just echo the command, then pause before running the command, not perfect, but it works:

ECHO java -jar crawler-1.0.jar
pause
java -jar crawler-1.0.jar
0
@echo off
cls
echo java -jar crawler-1.0.jar
echo Press ENTER to continue
pause > nul
<insert command to execute here after user press a button>
  1. line = standard start of batch-file
  2. line = clears the screen so that only your wanted text will appear
  3. line = displays the text you wanted
  4. line = tells the user what to do (it will actually activate regardless of key entered; you can't choose that) [optional of course]
  5. line = regular pause command - > nul does only hide the "press a key" in favour of your 4th line custom message, or no message at all
  6. line = enter your desired run code

I can't comment, so answer to comment question is here:

@echo off
:start
cls
echo java -jar crawler-1.0.jar
echo Press ENTER to continue
pause > nul
<insert command to execute here after user press a button>
goto start
WildOne
  • 1
  • 2
  • Then you have to add another pause command after your execute command to display whatever was executed before it returns to start OR move the :start command one step down and each run will stack up on the screen. – WildOne Apr 24 '15 at 22:30