For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > September 2006 > Korn Shell Script









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Korn Shell Script
Roman

2006-09-13, 7:02 pm

I am trying to set up an automatic execution of a java package which
accepts values from a number of prompts.

For instance,


The execution line is as follows:


[abc] ~/dfg > java -jar abc.jar


Platform Options Available:
[1] Windows
[2] Unix


Choose: 2


Database
[1] Oracle
[2] UDB


Choose: 1


etc...


How do I automatically run this using ksh without user input?


Thanks in advance

Chris F.A. Johnson

2006-09-13, 7:02 pm

On 2006-09-13, Roman wrote:
> I am trying to set up an automatic execution of a java package which
> accepts values from a number of prompts.
>
> For instance,
>
>
> The execution line is as follows:
>
>
> [abc] ~/dfg > java -jar abc.jar
>
>
> Platform Options Available:
> [1] Windows
> [2] Unix
>
>
> Choose: 2
>
>
> Database
> [1] Oracle
> [2] UDB
>
>
> Choose: 1
>
>
> etc...
>
>
> How do I automatically run this using ksh without user input?


If it reads from the standard input:

printf "%s\n" 2 1 | java -jar abc.jar

If not, you can use 'expect'.

--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
Roman

2006-09-13, 7:02 pm

Thanks for your help.

I have used expect, but it doesn't seem to work. Perhaps I code it
wrong. Here is the code

#!/usr/bin/expect
java -jar abc.jar
expect ".*"
send "2\r"
expect eof


Chris F.A. Johnson wrote:
> On 2006-09-13, Roman wrote:
>
> If it reads from the standard input:
>
> printf "%s\n" 2 1 | java -jar abc.jar
>
> If not, you can use 'expect'.
>
> --
> Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
> Shell Scripting Recipes: | My code in this post, if any,
> A Problem-Solution Approach | is released under the
> 2005, Apress | GNU General Public Licence


Roman

2006-09-13, 7:02 pm

Never mind. My mistake.

I didn't use spawn.

Roman wrote:[color=darkred]
> Thanks for your help.
>
> I have used expect, but it doesn't seem to work. Perhaps I code it
> wrong. Here is the code
>
> #!/usr/bin/expect
> java -jar abc.jar
> expect ".*"
> send "2\r"
> expect eof
>
>
> Chris F.A. Johnson wrote:

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com