0

This is my first post, please let me know if I did not provide enough information for you all.

First a little background info. I am a TA for a Computer Information Systems course and I am attempting to automate the grading of a very basic Java application our students will be writing.

For the sake of this conversation, the Java program I want to grade is a simple calculator that will calculate the non-compounding interest with 2 inputs (Principle and Interest Rate) provided by the user from a command line interface. It is important to note that the Java program will prompt the user to input the Principle and Interest Rate independently, and it cannot be provided as Command Line Arguments. Below is a quick snippet of what the Usage of the Java application looks like.

Please enter the principal amount of the loan as a Decimal. 

5 /User Input

Please the percentage rate for the loan as a Decimal.

5 /User Input

Total $:           5.25

I need this very basic PowerShell script to open the java application, wait for a prompt then input a integer, and then output the result to a text file.

At this point, my script will open the Java application, but it will not proceed to the next command until I complete the Java application. Below is the basic script I am using thus far.

add-type -AssemblyName System.Windows.Forms

java Interest

Start-Sleep -Milliseconds 500

[System.Windows.Forms.SendKeys]::SendWait("5")

[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")

exit

Again, this script will open the Java application and wait for me to provide an input variable opposed to submitting the '5' from the code snippet above.

If anyone has a little bit of guidance that will allow me to interact with the Java application CLI once it has been executed, I would greatly appreciate.

Thank you all for being patient as I fumble through my first post and these formatting issues. I look forward to hearing from you.

-Aaron

(Edit: Thanks to RamPrakash for helping with some of my formatting!)

Forrmatt
  • 11
  • 2
  • If it's a CLI application you can do better than sending keys to the Window, you can write directly to its standard input and read from its standard output. e.g. http://stackoverflow.com/a/16100200/478656 and http://stackoverflow.com/a/8762068/478656 – TessellatingHeckler Feb 01 '17 at 22:45
  • Hey TessallatingHeckler, thanks for the quick reply. I am attempting a few of the ideas in the links you posted (thanks again btw), but I am still running into the same problem. The next line after 'java interest' will not execute until I manually enter the parameters for the java application. Is there a way to interject integers from the script into the running application? – Forrmatt Feb 01 '17 at 23:38
  • Not sure I get what you mean; anywhere you can write a string, you can write a variable instead -> `$p.StandardInput.WriteLine("dir")` becomes `$p.StandardInput.WriteLine($myInt)` instead, or `$p.StandardInput.WriteLine("$myInt")` to force it to be a string... – TessellatingHeckler Feb 01 '17 at 23:48

0 Answers0