Giter Club home page Giter Club logo

jpty's Introduction

JPty - A small PTY interface for Java.

This library provides a simply interface for using pseudo terminals (PTYs) in Java, allowing one to communicate with processes as if they are running in a "real" terminal.

Dependencies

This library depends on JTermios, part of the PureJavacomm library found at https://github.com/nyholku/purejavacomm. A binary release of this library, along with its dependency JNA, is made part of this repository, and can be found in the lib-directory.

Usage

Using this library is relatively easy:

// The command to run in a PTY...
String[] cmd = { "/bin/sh", "-l" };
// The initial environment to pass to the PTY child process...
String[] env = { "TERM=xterm" };

Pty pty = JPty.execInPTY( cmd[0], cmd, env );

OutputStream os = pty.getOutputStream();
InputStream is = pty.getInputStream();

// ... work with the streams ...

// wait until the PTY child process terminates...
int result = pty.waitFor();

// free up resources.
pty.close();

The operating systems currently supported by JPty are: FreeBSD, Linux, OSX and Solaris.
Note that this library is not yet fully tested on all platforms.

Changes

0.0.5 | 15-02-2013 | Initial version.
0.1.0 | 01-06-2013 | Fixed an issue with prematurely closing a PTY while
      |            | the child process is still running. Thanks to traff
      |            | for reporting this.

Author

This library is written by J.W. Janssen, [email protected].

License

The code in this library is licensed under Apache Software License, version 2.0 and can be found online at: http://www.apache.org/licenses/LICENSE-2.0.

jpty's People

Contributors

jawi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

jpty's Issues

create project module

Could be nice to be able to build project (and download dependencies) via a console build, e.g. maven or gradle

Read from Pty.getInputStream() hangs

Sometimes read from Pty stream hangs. Have you experienced that? What exactly can cause it?
That is a corresponding dump:

"ConnectRunnable@1796" prio=5 tid=0x13 nid=NA runnable
  java.lang.Thread.State: RUNNABLE
      at jtermios.linux.JTermiosImpl$Linux_C_lib_DirectMapping.read(JTermiosImpl.java:-1)
      at jtermios.linux.JTermiosImpl.read(JTermiosImpl.java:557)
      at jtermios.JTermios.read(JTermios.java:411)
      at jpty.Pty$1.read(Pty.java:132)
      at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264)
      at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306)
      at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158)
      - locked <0x717> (a java.io.InputStreamReader)
      at java.io.InputStreamReader.read(InputStreamReader.java:167)

InputStreamReader here is created on Pty.getInputStream()

I experience the hang both on Ubuntu Linux and Mac OSX 10.7.5, but maybe I'm doing something wrong.
The most suspecious thing is that the problem began to appear more often - I have it in 99% on my Mac while debugging. Before(I don't know when it changed) it was not so often.

Also sometimes I get following exception

java.io.IOException: Underlying input stream returned zero bytes
    at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:268)
    at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306)
    at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158)
    at java.io.InputStreamReader.read(InputStreamReader.java:167)
    at com.jediterm.terminal.ProcessTtyConnector.read(ProcessTtyConnector.java:47)
...

Pty.close() doesn't stop the process

  1. I create Pty by JPty.execInPTY(command, arguments, environment).
  2. I invoke Pty.close() method

Result: Slave fd isn't closed, process isn't stopped, Pty.waitFor hangs
Expected: Process is stopped, Pty.waitFor returns exit code.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.