问题
I have a jar
file which when run from command prompt works well, I mean it asks for user input,but when the same is run from psexec
or powershell
or jenkins
doesn't accept values and starts processing further commands.
In short: When jar is executed, there is a menu to make choices. If choice is within specific range, it works well else gives message entered value is not valid
. Here I am getting the message in a loop. Can anyone suggest where I am going wrong or need to make any change in the settings.
P.S.~ I am trying to execute commands on remote machine and I am calling the jar using java -jar myFile.jar
回答1:
can you give a basic idea how I can achieve it in Jenkins.
So
- if your jar accepts arguments you pass them in the jenkins job via Parameterized Builds
- if it doesn't but instead prompts you, you are in problem: you need a way to automate console then.
Automate console
X-platform tool for the job is Expect. Bad thing about it is that it requires a lot of deps on Windows (if you are running this on Linux expect is probably already there). As alternative you could use Autohotkey altho it can't detect easily console text (unlike expect which reads console buffer). However if prompt appears in deterministic manner (i.e. just after start) you could do something like:
java -jar myfile.jar
sleep 5
autohotkey.exe SendKeys.ahk
SendKeys.ahk would be as simple as:
WinActivate <pid / window name ...>
Send answer1<ENTER>answer2<ENTER> ....
but it could be made more robust so that key sending will not depend on console window state.
In cmd you can set some specific window name with title
command then you can activate that title with AHK.
来源:https://stackoverflow.com/questions/36762877/jar-not-accepting-values