The essence of the problem: There is a jar program that needs to be restarted once an hour. To start it, first enter the number 1 in the console menu and press Enter, then enter the port where the program should start and press Enter.

I tried to transfer echo 1 through the pipe and tried the construction

java -jar jar.jar < nul set /p str="1" 

but it did not help.

Is there a way to do this from bat or by any other means?

  • use nircmd.exe - Dred
  • and what does the program do? - Stranger in the Q
  • one
    sentence number 1 - modify the program to run without keyboard input - Stranger in the Q
  • First you need to write to the console, and then read from it, and not vice versa. - Roman C
  • @Dred is an interesting thing, but I did not find any of its features that could help me. Can you tell? - Danil Manmarev

2 answers 2

Create a param.txt file with the following contents:

 1 1234 

1234 is the port number.

Run like this: java -jar jar.jar < param.txt .

  • this did not help, now the menu is infinitely displayed) - Danil Manmarev
  • Perhaps the program you are using does not read from the input stream, but directly refers to the console. In this case, there is no easy way to give her something. Look in the documentation, maybe it accepts parameters or reads configs. - talex
  • Alas, no arguments, no config. - Danil Manmarev
  • Try decompiling and see what's inside. - talex

Download nircmd.exe from here create a script file. In it you place code, for example,

 cmdwait 2000 sendkey enter press sendkey 1 press sendkey enter press cmdwait 2000 sendkey enter press sendkey 8080 press sendkey enter press 

In my case, I put nircmd.exe and the msg.ncl file along the path C: \ nircmd. The start command will look like this

 C:\nircmd>nircmd.exe script msg.ncl 

As a result, you will launch the script, wait 2 seconds and press 1, then wait another 2 seconds, press again, let's say port 8080 and press inter. Theoretically, maybe you only have enough of these lines.

 sendkey 1 press cmdwait 2000 sendkey 8080 press 

I did not have the opportunity to test locally, since I do not know what code you are taking these commands.

Through the standard Windows Scheduler make the command run

  C:\nircmd>nircmd.exe script msg.ncl 

once an hour Everything.

Read the instructions on the page where to download the program itself. Maybe something else interesting and useful will seem to you.

  • that's how monsters are born wrapped with tape and wire, just to work - Stranger in the Q
  • Well, yes) But if there is no way to fix it. I had to start every day the software that launches the searchlights, and turn them off in the evening. Software from a third-party company. So, with the help of nircmd, the software opened, unfolded on the whole screen and emulated mouse clicks in different coordinates, where there were keys for switching on the spotlights and launching different "programs" of the spotlights to work) this is what he does. - Dred