简体   繁体   中英

Insert input in Eclipse console - Java

here's my problem. I have a server that is started inside Eclipse, so the process is always running until I kill it.

If I want to execute a clean shutdown, I can write "shutdown" directly in the eclipse console and press enter. I need a clean shutdown (and not just a taskkill) because the server is supposed to send a snmp trap before it closes.

What I want to know is, is it possible that the "shutdown" could be written in the console as an input directly from a java method ( stopServer() )?

This is for tests purpose and it has to be automated. And there is no possibility to write a script that would do that.

Thank you.

Unless you are not sure that your server can read the input command why even bother doing it with the text command? The text command is only a human readable/interactive form of the functioncall right? Maybe I don't really get what you want, but to me it seems easier to just write a signalhandler that always does the clean shutdown.

If you really wanted to do it, you could probably do it by writing to STDIN though (basicly what the console does).

Is this a JavaEE server you're setting up and tearing down? If so have you looked into Cargo ? It has lots of functionality to setup, deploy, and tear down containers both in code (in your JUnit beforeClass/afterClass) and/or through a maven plugin as well.

How about the stopServer() method containing all the shutdown logic, and making the shutdown command just another way to call the stopServer() method. That is way easier than sending the command to the console.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM