{"id":4696,"date":"2014-03-30T14:45:35","date_gmt":"2014-03-30T14:45:35","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/java-detecting-user-prompt-when-running-a-batch-script-from-java-collection-of-common-programming-errors\/"},"modified":"2014-03-30T14:45:35","modified_gmt":"2014-03-30T14:45:35","slug":"java-detecting-user-prompt-when-running-a-batch-script-from-java-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/java-detecting-user-prompt-when-running-a-batch-script-from-java-collection-of-common-programming-errors\/","title":{"rendered":"Java: Detecting user prompt when running a batch script from Java-Collection of common programming errors"},"content":{"rendered":"<p>I need to execute from Java a batch script, which does following<\/p>\n<p>1) Once it is started it performs a lengthy (up to several seconds) task.<\/p>\n<p>2) Thereafter, it displays a prompt &#8220;Password:&#8221;.<\/p>\n<p>3) Then, the user types in the password and presses the Enter key.<\/p>\n<p>4) Then, the script completes its job.<\/p>\n<p>I know how to launch the script from Java, I know how to read output of the batch script in Java, but I don&#8217;t know how to wait for the password prompt to appear (how I get to know that the batch script is awaiting the password entry).<\/p>\n<p>So, my question is: How to get to know when the batch script has printed the prompt?<\/p>\n<p>At the moment, I have following code:<\/p>\n<pre><code>final Runtime runtime = Runtime.getRuntime();\nfinal String command = ... ;\n\nfinal Process proc = runtime.exec(command, null, this.parentDirectory);\n\nfinal BufferedReader input = new BufferedReader(new InputStreamReader(\n  proc.getInputStream()));\n\nString line = null;\n\nwhile ((line = input.readLine()) != null) {\n LOGGER.debug(\"proc: \" + line);\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I need to execute from Java a batch script, which does following 1) Once it is started it performs a lengthy (up to several seconds) task. 2) Thereafter, it displays a prompt &#8220;Password:&#8221;. 3) Then, the user types in the password and presses the Enter key. 4) Then, the script completes its job. I know [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4696","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4696","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4696"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4696\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4696"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4696"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4696"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}