how to get Java cmd/terminal/shell program to release? -
public static void main(string[] args){ system.out.println("enter password"); char[] password = system.console.readpassword(); if(passwordok(password)){ //let go of shell, , continue running. } } i want java application keep on running, stop "hogging" cmd/terminal. release cmd/terminal can use per normal, while application continues run. no more terminal usage after password auth/setup.
i don't think running process can switch itself foreground background, detaching input , output. suitably sophisticated shell can, of course, use job management background running tasks (in unix shells, ctrl-z, fg, bg etc.).
in java best can think of write 2 programs:
- your long-running server runs in background, , starts opening
serversocket, listens 1 connection, on expects receive authentication info. when has happened initialise , go main listening loop. - another program runs in foreground. waits socket become available, connects, prompts @ terminal password, writes socket, closes , terminates
you'll need simple scripting launch both programs @ same time. there's no reason why both programs have java -- on unix i'd tempted use netcat squirt password server.
for security, ensure socket uses localhost networking. on unix instead unix domain socket.
of course there lots of communication methods 2 processes use -- files, shared memory, pipes, tcp sockets, ... -- it's matter of picking 1 that's secure enough information you're passing between them.
Comments
Post a Comment