ExpectIt
ExpectIt copied to clipboard
some problem with sendLine()
Hello
I have some problem with expectit and jsch using expect.sendLine() function
that's error when send "find . -type f \\( -name \"*.1\" -o -name \"*.2\" \\) | wc -l"
origianl command(no java escape) : "find . -type f \( -name "*.1" -o -name "*.2" \) | wc -l"
result error:prompt]find . -type f \( -name "*.1" -name "*.2 prompt]ame "*.1" -name "*.2" < \) | wc -l
- why entered new line?
- what
"< "
I use expectit-core-0.9.0.jar and jsch-0.1.55.jar and hpux 11.31 ksh
Cam you please include a source code snippet? Are you waiting for the prompt after sendLine command?
`package sshProxy;
import static net.sf.expectit.matcher.Matchers.contains;
import org.apache.commons.lang3.StringUtils; import org.joda.time.DateTime; import org.slf4j.Logger;
import net.sf.expectit.Expect;
public class ShellUtils { public static final String COMMAND_FIND_EXMS_ATTATCH = "find . -type f \( -name ".1"-o -name ".2" \) | wc -l";
public static void countEmxsAttach(DateTime startDate, DateTime endDate, DateTime maxRuntime, String prompt, String path,
Logger log, Expect expect) throws Exception {
String result = null;
String[] lines = null;
String count = null;
if(startDate.isAfter(endDate)) {
log.error("time error");
return;
}
// Month
for (int month = startDate.getMonthOfYear(); month <= 12; month++) {
int lastDayOfMonth = startDate.dayOfMonth().getMaximumValue();
for (int day = startDate.getDayOfMonth(); day <= lastDayOfMonth; day++) {
if (DateTime.now().isAfter(maxRuntime)) {
log.info("MAX RUNTIME:{}", DateTime.now());
throw new Exception("time over");
}
String baseDir = String.format(path, month, day);
String curruntDir = prompt + baseDir;
expect.sendLine("cd " + baseDir);
expect.expect(contains(curruntDir));
expect.sendLine(COMMAND_FIND_EXMS_ATTATCH);
result = expect.expect(contains(curruntDir)).getBefore();
lines = StringUtils.split(result, StringUtils.LF);
count = StringUtils.trim(lines[1]);
log.info("ATTATCH:{}\t{}\t{}", baseDir, count);
startDate = startDate.plusDays(1);
if (startDate.isAfter(endDate)) {
log.info("MAX RUNTIME:{}", DateTime.now());
return;
}
}
}
}
}`
main Class call above "countEmxsAttach" ssh connected and close connection in main class.