Is it possible to grab system.out.print from java program in csh variable?

I know this is a lame way to do it. We need to write a string dynamically generated in the Java program in the calling shell script and then use it later.

Also this must be done in an existing csh file.

We looked into exporting it to an environment variable using putenv / setenv ... is this the best option? If so, how do you use it?

There seems to be no example code on the net on how to effectively use sentenv () or putenv () and which libraries to import for them.

System class with getenv () method doesn't show my putenv () or setenv (). Any help is appreciated.

Thanks.

+1


a source to share


2 answers


You should simply use command substitution using the backtick syntax, just like in bash (in bash currently, it is recommended to use the more convenient $ -syntax). For instance:

$ set A=`java MyProgram`
$ echo $A

      

or something very similar



You cannot use the environment; it is impossible to use "back" using it; the child process cannot change the parent environment.

UPDATED : Added 'set' keyword in example, d'oh.

+2


a source


Extending from first answer:

You might want to do this: $ A = java MyProgram | grep <something>

$ echo $ A

where you want to capture, assuming MyProgram outputs more than one line.



If the java program uses System.err.print ... instead of System.out.print .... you need $ A = java MyProgram 2>&1 | grep <something>

hope this helps :-)

0


a source







All Articles