0

I have the following working from the console:

COMPUTER LINUX: nc -l -p 5012 | mplayer -fps 31 -cache 1024 -
RPI:  raspivid -t 2000 -o - | nc 192.168.0.5 5012

But then if I try and wrap it in Java it doesn't work. It doesnt crash, it runs through till the end of the program just nothing happens:

public void video() {
    try {
        String[] cmds = {"/bin/sh", "-c", "nc -l -u 5012 | mplayer -fps 31 -cache 1024 -"};
        Process videoProcess = Runtime.getRuntime().exec(cmds);
        adder.streamVideo(2000);
     catch (IOException e) {
    System.out.println("IOE");
    e.printStackTrace();
    }
}

where adder.streamVideo() calls the RPI code.

public boolean streamVideo(int streamDuration) {
    String[] cmd = {"/bin/sh", "-c",
            "raspivid -t " + streamDuration + " -o - | nc 192.168.0.5 5012"};
    try {
        Runtime.getRuntime().exec(cmd);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        System.out.println("Video streaming failed");
        e.printStackTrace();
    }
    return true;
}

Any suggestions?

cxzp
  • 652
  • 2
  • 14
  • 28

1 Answers1

0

exec() does not summon a shell, so all shelly things like pipes | and output/input redirection > and < will not work. but your problem is solvable, see e.g. https://stackoverflow.com/a/5928316/2536029

Community
  • 1
  • 1
mnagel
  • 6,729
  • 4
  • 31
  • 66
  • i have changed the code as you suggested due to exec() not summoning a shell and have instead put it in a script, it still isnt working - the code above reflects the changes made – cxzp Sep 10 '13 at 14:07
  • nothing crashes it runs just nothing happens, i know that the video code is fine as i have run that code on the rpi end and it works from a shell so im not sure why it still doesnt work – cxzp Sep 10 '13 at 14:13