微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法通过 SSH 执行 Cutrite 命令

如何解决无法通过 SSH 执行 Cutrite 命令

我正在尝试使用 SSH 执行一些 Cutrite 命令。这些命令在目标机器上直接执行时运行良好,但不能通过代码运行。这些命令不会返回任何输出错误,我可以通过这些输出错误找到问题的根本原因。我也试过运行 cdpwd 之类的命令,它们工作正常。


import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;
import net.sf.expectit.Expect;
import net.sf.expectit.ExpectBuilder;

import java.util.ArrayList;
import java.util.Date;
import java.util.Hashtable;
import java.util.List;

public class SSHTest {

    public static void main(String[] args) {

        String fileNameWithOutExt = "cutrite1614835697251";
        try {
            JSch jsch = new JSch();
            Session session = jsch.getSession(username,host);
            session.setPassword(password);

            Hashtable<String,String> config = new Hashtable<String,String>();
            config.put("StrictHostKeyChecking","no");
            session.setConfig(config);
            session.connect(60000);

            ChannelExec channel = (ChannelExec) session.openChannel("exec");
            Expect expect = new ExpectBuilder()
                    .withInputs(channel.getExtInputStream())
                    .withOutput(channel.getoutputStream())
                    .build();
            channel.connect();

            List<String> lstCmds = new ArrayList<String>();
            lstCmds.add("cd C:\\V11\\Inch");
            lstCmds.add("C:\\V11\\IMPORT.EXE " + fileNameWithOutExt + " /AUTO /OVERWRITE | Out-Null");
            lstCmds.add("C:\\V11\\BATCH.EXE \"" + fileNameWithOutExt + ".PRL\" /AUTO /OPTIMISE | Out-Null");
            lstCmds.add("C:\\V11\\OUTPUT.EXE /XLS /REPORTS=E");

            for (String strCmd : lstCmds) {
                expect.sendLine(strCmd);
                expect.sendLine("\r");//enter character
            }
            expect.close();
        } catch (Exception e) {
            e.printstacktrace();
        }
    }
}```

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。