public void run() { InputStream is = pty.getInputStream(); try { int ch; while (pty.isRunning() && (ch = is.read()) >= 0) { if (ch >= 0) { readChars.incrementAndGet(); } } } catch (Exception e) { e.printStackTrace(); } } };
public void run() { try { Scanner s = new Scanner(pty.getInputStream()); while (s.hasNextLine()) { System.out.println(s.nextLine()); } result[0] = pty.waitFor(); latch.countDown(); } catch (InterruptedException e) { // Simply stop the thread... } } };
public void run() { InputStream is = pty.getInputStream(); try { int ch; while (pty.isRunning() && (ch = is.read()) >= 0) { if (ch >= 0) { readChars.incrementAndGet(); } } } catch (Exception e) { e.printStackTrace(); } } };
public void run() { InputStream is = pty.getInputStream(); try { int ch; while (pty.isRunning() && (ch = is.read()) >= 0) { if (ch >= 0) { System.out.write(ch); System.out.flush(); } } latch.countDown(); } catch (Exception e) { e.printStackTrace(); } } };
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()); }