Opening a UNIX shell in Java


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Opening a UNIX shell in Java
# 1  
Old 08-13-2007
Opening a UNIX shell in Java

Hi,
I need to simulate the machine's native shell (sh), for that I open up a UNIX shell in my Java program.
My code works fine with windows shell ('cmd') but with unix ('sh') I failed to retrieve the machine's prompt.
I believe that the issue is unix-related and that the process I launched has no appropriate environment parameter, so i need the expert's opinion on that Smilie.

These are the environment's variables as printed by the user:
Code:
# set
HOME=/
HZ=100
IFS=

LC_COLLATE=en_US.ISO8859-1
LC_CTYPE=en_US.ISO8859-1
LC_MESSAGES=C
LC_MONETARY=en_US.ISO8859-1
LC_NUMERIC=en_US.ISO8859-1
LC_TIME=en_US.ISO8859-1
LOGNAME=root
MAIL=/var/mail/root
MAILCHECK=600
OPTIND=1
PATH=/usr/sbin:/usr/bin
PS1=#
PS2=>
SHELL=/sbin/sh
TERM=ansi
TZ=Israel
_INIT_NET_STRATEGY=none
_INIT_PREV_LEVEL=S
_INIT_RUN_LEVEL=3
_INIT_RUN_NPREV=0
_INIT_UTS_ISA=sparc
_INIT_UTS_MACHINE=sun4u
_INIT_UTS_NODENAME=DEVSSSUN01
_INIT_UTS_PLATFORM=SUNW,Ultra-5_10
_INIT_UTS_RELEASE=5.8
_INIT_UTS_SYSNAME=SunOS
_INIT_UTS_VERSION=Generic_108528-13

The following are the environment's variables as printed by my java app:
Code:
_INIT_UTS_VERSION:Generic_108528-13
XFILESEARCHPATH:/usr/dt/app-defaults/%L/Dt
HZ:100
LC_CTYPE:en_US.ISO8859-1
NLSPATH:/usr/dt/lib/nls/msg/%L/%N.cat
LC_COLLATE:en_US.ISO8859-1
HOME:/
_INIT_UTS_ISA:sparc
_INIT_RUN_LEVEL:3
_INIT_UTS_RELEASE:5.8
LC_NUMERIC:en_US.ISO8859-1
LD_LIBRARY_PATH:/usr/java1.5/jre1.5.0_09/lib/sparc/client:/usr/java1.5/jre1.5.0_
09/lib/sparc:/usr/java1.5/jre1.5.0_09/../lib/sparc
SHELL:/sbin/sh
LOGNAME:root
_INIT_UTS_MACHINE:sun4u
_INIT_PREV_LEVEL:S
_INIT_UTS_NODENAME:DEVSSSUN01
LC_MONETARY:en_US.ISO8859-1
_INIT_RUN_NPREV:0
MAIL:/var/mail/root
TZ:Israel
LC_TIME:en_US.ISO8859-1
_INIT_UTS_PLATFORM:SUNW,Ultra-5_10
_INIT_NET_STRATEGY:none
LC_MESSAGES:C
_INIT_UTS_SYSNAME:SunOS
TERM:ansi
PATH:/usr/sbin:/usr/bin

And these are the environment's variables as printed by the user in the shell that was launched by the java app:
Code:
HOME=/
HZ=100
IFS=

LC_COLLATE=en_US.ISO8859-1
LC_CTYPE=en_US.ISO8859-1
LC_MESSAGES=C
LC_MONETARY=en_US.ISO8859-1
LC_NUMERIC=en_US.ISO8859-1
LC_TIME=en_US.ISO8859-1
LD_LIBRARY_PATH=/usr/java1.5/jre1.5.0_09/lib/sparc/client:/usr/java1.5/jre1.5.0_
09/lib/sparc:/usr/java1.5/jre1.5.0_09/../lib/sparc
LOGNAME=root
MAIL=/var/mail/root
MAILCHECK=600
NLSPATH=/usr/dt/lib/nls/msg/%L/%N.cat
OPTIND=1
PATH=/usr/sbin:/usr/bin
SHELL=/sbin/sh
TERM=ansi
TZ=Israel
XFILESEARCHPATH=/usr/dt/app-defaults/%L/Dt
_INIT_NET_STRATEGY=none
_INIT_PREV_LEVEL=S
_INIT_RUN_LEVEL=3
_INIT_RUN_NPREV=0
_INIT_UTS_ISA=sparc
_INIT_UTS_MACHINE=sun4u
_INIT_UTS_NODENAME=DEVSSSUN01
_INIT_UTS_PLATFORM=SUNW,Ultra-5_10
_INIT_UTS_RELEASE=5.8
_INIT_UTS_SYSNAME=SunOS
_INIT_UTS_VERSION=Generic_108528-13

Note that there is no prompt's variable (SP1) for the java app and\or the process that was launched by it.

Any idea?
Thanks in advance.
Guy
# 2  
Old 08-13-2007
Quote:
Originally Posted by guyi
I believe that the issue is unix-related and that the process
Most likely the shell has determined that it is not connected to a terminal, and hence is "non-interactive", so it does not print the prompts.
# 3  
Old 08-13-2007
Can I change the shell's "non-interactive" mode to an "interactive"? Can I "trick" him, or this is it and there is nothing to do? although I believe that it should be a solution.

Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Opening a Unix File with Mac OS X

Hi. I'm new to Unix and recently received Unix files via email. I downloaded those files but am unable to open them on my computer which uses Mac OS X. How do I open the files? (11 Replies)
Discussion started by: michellemc
11 Replies

2. Shell Programming and Scripting

how to execute a unix shell script from a java program

Hi All, well , i am facing this problem.. i have tried a few sample codes but there isn't any solution . could anyone please give a sample code as of how to do this... Please see the below details...and read the details carefully. I have written some code, logic is 1)from... (4 Replies)
Discussion started by: aish11
4 Replies

3. Shell Programming and Scripting

Help with opening another file from within a shell script

Hi, I am trying to open a file that I have created from withn a shell script and cannot seem to get it working. Does anyone have any ideas? Thanks. (2 Replies)
Discussion started by: tdsrogers
2 Replies

4. Shell Programming and Scripting

Calling Java Method from UNIX using shell script

Hi All, I need to call a java method from a shell script. I know we can use the command java ClassName to call the main method in it. But I need to call another method that is there in the class and pass an email to it. Can I use java ClassName.MethodName(email) Any help will be... (4 Replies)
Discussion started by: RahulK
4 Replies

5. UNIX for Dummies Questions & Answers

Java or C for creating a unix shell?

Hi, Great to find this forum! I'm a complete newbie to unix, and am having a hard time finding my way around. Firstly, I've been reading something about c shell programming being one tenth the size of c programming done on unix.....I couldn't figure what that meant, but there were two... (7 Replies)
Discussion started by: sdsd
7 Replies

6. Shell Programming and Scripting

Unix Shell script vs Java

Members, I been faced with an issue where i have to sale my project against JAVA.would like to know more on the strong point of shell script (bash shell) over java.I have a very limited knowledge on java.is there anyone who has worked on java and shell scripting in both and really been able to... (13 Replies)
Discussion started by: navojit dutta
13 Replies

7. Programming

exit status running java classpath in unix shell

I have a java classpath running inside of a unix shell script. During my testing it will error with lines that show an example like this below. java.io.FileNotFoundException error at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.<init>(FileInputStream.java:129), ... (2 Replies)
Discussion started by: mmcds
2 Replies

8. Programming

Opening a TCPIP Port with UNIX C

i am new to UNIX and C (primarilly a JDE and AS400/RPG developer). However, I need to find a way to send data to and from a web service from within a UNIX C program. What i would like to be able to do is to receive in a block of XML (from a non C application), wrap it, and then open a TCPIP... (3 Replies)
Discussion started by: DaveBarber
3 Replies

9. Programming

File Opening in C++ in Unix Env

Pls someone help me. This piece of code is giving me weird results. ofstream outfile; ofstream out; char filename1; char filename2; memset(filename1,'\0',sizeof(filename1)); memset(filename2,'\0',sizeof(filename2)); strcpy(filename1,"Testing1.out");... (0 Replies)
Discussion started by: skannan
0 Replies
Login or Register to Ask a Question