linphone-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Linphone-users] Calling linphonec from Java - what changed between 3.7.


From: Adam Granger
Subject: [Linphone-users] Calling linphonec from Java - what changed between 3.7.0 and 3.9.1?
Date: Tue, 26 Jan 2016 13:36:58 -0100
User-agent: SquirrelMail/1.4.21

>From my recent stackoverflow post
(http://stackoverflow.com/questions/35014744/unable-to-write-into-a-console-application)

I'm invoking linphonec.exe, an interactive console application for
controlling Linphone, an open source Skype-like application via Java
(1.8u11) on Windows 7.

Everything worked fine in Linphone 3.7.0, however after updating to 3.9.1,
I can no longer invoke commands from Java into the application. Linphonec
just ignores the commands

Small example to recreate, issuing the help command..

public class CommandTest {
    private static class Consumer implements Runnable {
        private InputStream stream;
        public Consumer(InputStream stream) {
            this.stream = stream;
        }
        @Override
        public void run() {
            int c = 0;
            try {
                while ((c = stream.read()) != -1) {
                    System.out.print((char) c);
                }
                System.out.println("Stream finish");
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) throws Exception {
        ProcessBuilder builder = new ProcessBuilder(
                Arrays.asList("C:\\Program Files
(x86)\\Linphone\\bin\\linphonec.exe"));
        builder.redirectInput(Redirect.PIPE);
        Process process = builder.start();
        new Thread(new Consumer(process.getInputStream())).start();
        new Thread(new Consumer(process.getErrorStream())).start();
        BufferedWriter stdin = new BufferedWriter(new
OutputStreamWriter(process.getOutputStream(),
StandardCharsets.US_ASCII));
        stdin.write("help\n");
        stdin.flush();
        process.waitFor();
    }
}

Output - with 3.7.0

Ready
Warning: video is disabled in linphonec, use -V or -C or -D to enable.
linphonec> Commands are:
---------------------------
      help  Print commands help.
      call  Call a SIP uri or number
      ... etc...

Output - with 3.9.1

Ready
linphonec> linphonec>

    I believe I'm following best practices for consuming all standard out
and error on separate threads as per the classic JavaWorld article
    I was using BufferedReader but simplified to input stream
    Explicitly specified character set - is this correct for a Windows
command line application?
    I note that if I write \n to the stream then linphonec simply responds
with linphonec>, so it definitely getting something...
    Manually tested the 3.9.1 installation on the command line - works fine
    Tried different combinations of \r, \n etc.

Out of desperation I even tried this, which didn't work in 3.9.1, only 3.7.0

for (char c : "help\n".toCharArray()) {
    stdin.write(c);
    stdin.flush();
    Thread.sleep(100);
}

If you set ProcessBuilder to inherit IO with
builder.redirectInput(Redirect.INHERIT) then with 3.7.0 you can type into
the eclipse console and it works as expected, however with 3.9.1 it fails
in the same way it does as manually calling write() on outputStream

Questions

    Is there some way an application can read from the console which is
not supported by ProcessBuilder
    Am I doing something obviously wrong
    Anyone have any success integrating with Java using this approach and
recent versions of Linphone Desktop...

Any ideas... I've been looking at the source at
https://github.com/BelledonneCommunications/linphone/blob/3.9.x/console/linphonec.c,
however it's pretty complicated....

Can anyone explain whether "readline" is used in Windows build and what
_WIN32_WCE would be set to in the Windows build?

Thanks,

Adam.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]