Skip to content
Advertisement

JSch: Is there a way to expose user environment variables to “exec” channel?

I am trying to run commands which uses local Linux logical paths like cat $test_dir/test.dat, but the logical path $test_dir (which is a user environment variable) is not available via ChannelExec. But when I use interactive ChannelShell, I am able to see the user variables and the commands run fine on the interactive session. I can view system level environment variable only from “exec” session. Is that even possible using JSch library, if yes then how shall I achieve it and if not what library shall I use to achieve this?

Adding my class code below:

JavaScript

Advertisement

Answer

Since you’re not opening up an interactive shell, your environment variables won’t be set. However, you can use the bash command with –login (man bash for more details) to get the results you want

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement