Search code examples
javacsh

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


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

Also this is to be done in an existing csh file.

We considered the option of exporting it to an environment variable using putenv/setenv ... is that a better option? If so how to use it?

There seems to be lack of example code on net on how to effectively use sentenv() or putenv() and what libraries to import for the same.

System class that has the getenv() method does not show my putenv() or setenv(). Any help is highly appreciated.

Thanks.


Solution

  • You should be able to just use command substitution, using backtick syntax just as in bash (in bash nowadays, the more usable $-syntax is recommended). Like so:

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

    or something very similar

    You cannot use the environment; it's not possible to communicate "backwards" using it; a child process cannot change the parent's environment.

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