assertEquals("Unexpected process result!", 0, result[0]);
/** * Tests that getting and setting the window size for a file descriptor works. */ public void testGetAndSetWinSize() throws Exception { String[] cmd = TestUtil.getJavaCommand(RepeatTextWithTimeout.class, "2", "1000", "Hello, World"); PtyProcess pty = PtyProcess.exec(cmd); WinSize ws = new WinSize(); ws.ws_col = 120; ws.ws_row = 30; pty.setWinSize(ws); WinSize ws1 = pty.getWinSize(); assertNotNull(ws1); assertEquals(120, ws1.ws_col); assertEquals(30, ws1.ws_row); pty.waitFor(); }
public void testExecCat() throws Exception { if (Platform.isWindows()) { return; } PtyProcess pty = new PtyProcessBuilder(new String[]{"cat"}).start(); Gobbler stdout = startReader(pty.getInputStream(), null); assertTrue("Process terminated unexpectedly", pty.isRunning()); pty.getOutputStream().write("Hello".getBytes(StandardCharsets.UTF_8)); pty.getOutputStream().flush(); Thread.sleep(1000); assertEquals("Hello", stdout.getOutput()); PtyHelpers.getInstance().kill(pty.getPid(), PtyHelpers.SIGPIPE); Thread.sleep(1000); assertTrue("Process is alive unexpectedly", !pty.isRunning()); assertEquals(PtyHelpers.SIGPIPE, pty.exitValue()); }
public void testConsoleMode() throws Exception { String[] command; if (Platform.isWindows()) { File file = new File(TestUtil.getTestDataPath(), "console-mode-test1.bat"); assumeTrue(file.exists()); command = new String[] { "cmd.exe", "/c", file.getAbsolutePath() }; } else { File file = new File(TestUtil.getTestDataPath(), "console-mode-test1.sh"); assumeTrue(file.exists()); command = new String[] { "/bin/sh", file.getAbsolutePath() }; } PtyProcess pty = new PtyProcessBuilder(command).setConsole(true).start(); final CountDownLatch latch = new CountDownLatch(2); Gobbler stdout = startReader(pty.getInputStream(), latch); Gobbler stderr = startReader(pty.getErrorStream(), latch); assertTrue(latch.await(4, TimeUnit.SECONDS)); stdout.awaitFinish(); stderr.awaitFinish(); pty.destroy(); assertEquals("abcdefz\r\n", stdout.getOutput()); assertEquals("ABCDEFZ\r\n", stderr.getOutput()); }