public static PtyProcess exec(String[] command, Map<String, String> environment, String workingDirectory, boolean console, boolean cygwin, File logFile) throws IOException { PtyProcessBuilder builder = new PtyProcessBuilder(command) .setEnvironment(environment) .setDirectory(workingDirectory) .setConsole(console) .setCygwin(cygwin) .setLogFile(logFile); return builder.start(); } }
@Override public boolean isConnected() { return myProcess.isRunning(); }
public static PtyProcess exec(String[] command, Map<String, String> environment, String workingDirectory, boolean console) throws IOException { return exec(command, environment, workingDirectory, console, false, null); }
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()); }
/** * 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 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()); }
@Test public void testGettingWorkingDirectory() throws Exception { String[] cmd = TestUtil.getJavaCommand(RepeatTextWithTimeout.class, "1", "1000", "Hello, World\n"); String workingDir = new File("test\\testData").getAbsolutePath(); PtyProcessBuilder builder = new PtyProcessBuilder(cmd) .setDirectory(workingDir) .setConsole(false) .setCygwin(false); WinPtyProcess process = (WinPtyProcess) builder.start(); assertEquals(workingDir, trimTrailingSlash(process.getWorkingDirectory())); process.waitFor(); }
public WinPtyProcess(@NotNull PtyProcessOptions options, boolean consoleMode) throws IOException { this(options.getCommand(), convertEnvironment(options.getEnvironment()), options.getDirectory(), options.getInitialColumns(), options.getInitialRows(), consoleMode); }
@Override protected void resizeImmediately() { if (getPendingTermSize() != null && getPendingPixelSize() != null) { myProcess.setWinSize( new WinSize(getPendingTermSize().width, getPendingTermSize().height, getPendingPixelSize().width, getPendingPixelSize().height)); } }
public synchronized void setWinSize(WinSize winSize) { if (myClosed) { return; } boolean result = INSTANCE.winpty_set_size(myWinpty, winSize.ws_col, winSize.ws_row, null); if (result) { myLastWinSize = new WinSize(winSize.ws_col, winSize.ws_row, 0, 0); } }
@Deprecated public static int changeWindowsSize(int fd, int width, int height) { return changeWindowSize(fd, new WinSize(width, height)); }
@Deprecated public final void setTerminalSize(int width, int height) { setTerminalSize(new WinSize(width, height, 0, 0)); }
@Nullable public synchronized WinSize getWinSize() { // The implementation might be improved after https://github.com/rprichard/winpty/issues/153 WinSize size = myLastWinSize; if (myClosed || size == null) { return null; } return new WinSize(size.ws_col, size.ws_row, 0, 0); }
private static boolean WIFEXITED(int status) { return _WSTATUS(status) == 0; }
@Override public void setUp() throws Exception { super.setUp(); TestUtil.setLocalPtyLib(); }
public static PtyProcess exec(String[] command, Map<String, String> environment, String workingDirectory) throws IOException { return exec(command, environment, workingDirectory, false, false, null); }
public static PtyProcess exec(String[] command, Map<String, String> environment) throws IOException { return exec(command, environment, null, false, false, null); }
public static PtyProcess exec(String[] command) throws IOException { return exec(command, (Map<String, String>)null); }
@Deprecated public static PtyProcess exec(String[] command, String[] environment) throws IOException { return exec(command, environment, null, false); }