小编use*_*714的帖子

JSch:有没有办法将用户环境变量公开给“exec”通道?

我正在尝试运行使用本地 Linux 逻辑路径(例如 )的命令cat $test_dir/test.dat,但逻辑路径$test_dir(这是用户环境变量)无法通过ChannelExec. 但是当我使用 Interactive 时ChannelShell,我可以看到用户变量和命令在交互式会话上运行良好。我只能从“exec”会话中查看系统级环境变量。使用 JSch 库是否可以实现这一点,如果是,那么我该如何实现它,如果不是,我应该使用什么库来实现这一目标?

添加我的类代码如下:

    
    private static final Logger logger = LogManager.getLogger(SecureShell.class);
    
    private String uName;
    private String pWord;
    private String hName;
    private int port;
    
    private Session session = null;
    private Channel channel = null;
    
    /**Create an instance to start and stop the remote shell and execute commands
     * remotely via java.
     * 
     * @param uName
     *          host username 
     * @param pWord
     *          host password
     * @param …
Run Code Online (Sandbox Code Playgroud)

java ssh jsch

2
推荐指数
1
解决办法
3168
查看次数

标签 统计

java ×1

jsch ×1

ssh ×1