ExpectIt icon indicating copy to clipboard operation
ExpectIt copied to clipboard

some problem with sendLine()

Open ppsnumi opened this issue 5 years ago • 2 comments

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

  1. why entered new line?
  2. what "< "

I use expectit-core-0.9.0.jar and jsch-0.1.55.jar and hpux 11.31 ksh

ppsnumi avatar Aug 12 '19 11:08 ppsnumi

Cam you please include a source code snippet? Are you waiting for the prompt after sendLine command?

agavrilov76 avatar Sep 15 '19 13:09 agavrilov76

`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.

ppsnumi avatar Sep 16 '19 01:09 ppsnumi