@Deprecated public WinPtyProcess(String[] command, String[] environment, String workingDirectory, boolean consoleMode) throws IOException { this(command, convertEnvironment(environment), workingDirectory, consoleMode); }
private WinPtyProcess(@NotNull String[] command, @NotNull String environment, @Nullable String workingDirectory, @Nullable Integer initialColumns, @Nullable Integer initialRows, boolean consoleMode) throws IOException { try { myWinPty = new WinPty(joinCmdArgs(command), workingDirectory, environment, consoleMode, initialColumns, initialRows); } catch (PtyException e) { throw new IOException("Couldn't create PTY", e); } myInputStream = new WinPTYInputStream(myWinPty, myWinPty.getInputPipe()); myOutputStream = new WinPTYOutputStream(myWinPty, myWinPty.getOutputPipe(), consoleMode, true); if (!consoleMode) { myErrorStream = new InputStream() { @Override public int read() { return -1; } }; } else { myErrorStream = new WinPTYInputStream(myWinPty, myWinPty.getErrorPipe()); } }
@Test public void testChangingWorkingDirectory() throws IOException, InterruptedException { File testNodeScript = new File("test\\testData\\change-working-dir.bat"); Assert.assertTrue(testNodeScript.isFile()); String workingDir1 = testNodeScript.getAbsoluteFile().getParent(); String workingDir2 = testNodeScript.getAbsoluteFile().getParentFile().getParentFile().getParent(); String[] cmd = {testNodeScript.getAbsolutePath(), "1", workingDir2, "2"}; PtyProcessBuilder builder = new PtyProcessBuilder(cmd) .setDirectory(workingDir1) .setConsole(false) .setEnvironment(System.getenv()) .setCygwin(false); WinPtyProcess process = (WinPtyProcess) builder.start(); printProcessOutput(process); assertEquals(workingDir1, trimTrailingSlash(process.getWorkingDirectory())); if (process.waitFor(2, TimeUnit.SECONDS)) { Assert.fail("Process exited unexpectedly"); } assertEquals(workingDir2, trimTrailingSlash(process.getWorkingDirectory())); }
@NotNull public PtyProcess start() throws IOException { if (myEnvironment == null) { myEnvironment = System.getenv(); } PtyProcessOptions options = new PtyProcessOptions(myCommand, myEnvironment, myDirectory, myRedirectErrorStream, myInitialColumns, myInitialRows); if (Platform.isWindows()) { if (myCygwin) { return new CygwinPtyProcess(myCommand, myEnvironment, myDirectory, myLogFile, myConsole); } return new WinPtyProcess(options, myConsole); } return new UnixPtyProcess(options, myConsole); } }
@Test public void testCmdLineWithSpaces() { assertEquals( "C:\\Python35\\python.exe \"C:\\Program Files (x86)\\JetBrains\\PyCharm 5.0.2\\helpers\\pydev\\pydevd.py\"", WinPtyProcess.joinCmdArgs(new String[]{ "C:\\Python35\\python.exe", "C:\\Program Files (x86)\\JetBrains\\PyCharm 5.0.2\\helpers\\pydev\\pydevd.py" }) ); }
@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(); }
@Deprecated public static PtyProcess exec(String[] command, String[] environment, String workingDirectory, boolean console) throws IOException { if (Platform.isWindows()) { return new WinPtyProcess(command, environment, workingDirectory, console); } return new UnixPtyProcess(command, environment, workingDirectory, new Pty(console), console ? new Pty() : null); }
@Test public void testCmdLineWithSpacesAndQuotes() { assertEquals( "test \"\\\"quoted with spaces\\\"\"", WinPtyProcess.joinCmdArgs(new String[]{"test", "\\\"quoted with spaces\\\""}) ); }
public WinPtyProcess(@NotNull PtyProcessOptions options, boolean consoleMode) throws IOException { this(options.getCommand(), convertEnvironment(options.getEnvironment()), options.getDirectory(), options.getInitialColumns(), options.getInitialRows(), consoleMode); }