我能够执行Shell脚本命令Soap UI,并且不确定如何读取回声输出并将其存储到变量中。
group.torrents
包含以下命令
test1.sh
我能够执行Shell脚本命令Soap UI,并且不确定如何读取回声输出并将其存储到变量中。
CURRENTDATEONLY=`date +"%b %d, %Y"`
echo Current Date is: ${CURRENTDATEONLY}
sleep 10
期望是将I have tried below code, still not capturing the output.
def command = "C:/Program Files (x86)/PuTTY/putty.exe -ssh user@ip -pw pass -m C:/test1.sh"
def Process p = Runtime.getRuntime().exec(command);
p.waitFor()
BufferedReader is1 = new BufferedReader(new InputStreamReader(p.getInputStream()));
log.info is1
String line;
// reading the output
while ((line = is1.readLine()) != null)
log.info line ;
====================================================
Tried using jsch api as well, but no luck
import com.jcraft.jsch.*;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Scanner;
String user = "";
String pw = "";
String host = "";
int port = 22;
String remoteFile = "C:/test1.sh";
try {
JSch jsch = new JSch();
Session session = jsch.getSession(user, host, port);
session.setPassword(pw);
//session.setConfig("StrictHostKeyChecking", "no");
log.info("Establishing Connection...");
session.setTimeout(60000);
session.connect();
log.info("Connection established.");
log.info("Crating SFTP Channel.");
ChannelSftp sftpChannel = (ChannelSftp) session.openChannel("sftp");
sftpChannel.connect();
log.info("SFTP Channel created.");
InputStream inputStream = sftpChannel.get(remoteFile);
Scanner scanner = new Scanner(new InputStreamReader(inputStream))
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
log.info(line);
}
} catch (JSchException | SftpException e) {
e.printStackTrace();
}
变量存储到属性中