• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java ProcessBuilder problem.  RSS feed

 
Zee Ho
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why it printed the $MYVAR rather than abc.???



 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's because you're simply reading in the variable name, you need to use the Env class to get the environment variable that you want and retrieve its value.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What operating system are you using ?
 
James Sabre
Ranch Hand
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When using Runtime.exec() or ProcessBuilder, one has to understand that environment variable interpolation has to be done using a shell. This is one of the traps dealt with in the 4 sections of http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html. You would do well to read this and implement the recommendations.

As a minimum, your code needs to be modified to


but you should also handle the Process stderr as well as the stdout.

P.S. I have fixed your code for reading from the Process stdout. One should always take note of the number of bytes actually read.
[ November 13, 2008: Message edited by: James Sabre ]
 
Zee Ho
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks dude for your kindly reply, it helps.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!