开发者

How to Send a Password to Process in Java

开发者 https://www.devze.com 2023-03-08 05:38 出处:网络
I am launching a process from java to run a command for me. This process runs for a little while, then needs a password to continue. Now I know that I can write to the开发者_JAVA技巧 in stream of the

I am launching a process from java to run a command for me. This process runs for a little while, then needs a password to continue. Now I know that I can write to the开发者_JAVA技巧 in stream of the proces, but I am not quite sure how to detect when I need to write to it.

Possible solutions:

Is there a way that I can detect that the process is blocking?

Can I just write to the standard in immediately after executing the command and when the process hits a point when it needs it, it can just read from it?

Any other ideas?


It is not necessary to detect if the child process is blocking or not. If the child process is designed to block until input is provided to it via stdin, it will block until such input is provided.

It it necessary to keep in mind that the standard input, output and error buffer sizes are limited, and therefore it would be necessary for the child process to process the contents of the input buffer, and for the parent process to process the contents of the output and error buffers as soon as possible. Not doing so will result in the child process hanging.


Maybe you should get around the runas problem but not using runas. Google found me this: http://www.source-code.biz/snippets/c/1.htm Lets you pass your password at runtime....

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号