Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 5F59C200C12 for ; Sun, 5 Feb 2017 16:31:40 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 4DBAC160B59; Sun, 5 Feb 2017 15:31:40 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 6FA21160B32 for ; Sun, 5 Feb 2017 16:31:39 +0100 (CET) Received: (qmail 98875 invoked by uid 500); 5 Feb 2017 15:31:37 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Users List" Delivered-To: mailing list user@commons.apache.org Received: (qmail 98857 invoked by uid 99); 5 Feb 2017 15:31:37 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 05 Feb 2017 15:31:37 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id CA1F718043F for ; Sun, 5 Feb 2017 15:31:36 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 2.498 X-Spam-Level: ** X-Spam-Status: No, score=2.498 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HTML_MESSAGE=2, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_SORBS_SPAM=0.5, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd3-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=decampo-org.20150623.gappssmtp.com Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id HD8ACs0J1nRl for ; Sun, 5 Feb 2017 15:31:34 +0000 (UTC) Received: from mail-oi0-f44.google.com (mail-oi0-f44.google.com [209.85.218.44]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTPS id 560C65F30B for ; Sun, 5 Feb 2017 15:31:34 +0000 (UTC) Received: by mail-oi0-f44.google.com with SMTP id j15so35760906oih.2 for ; Sun, 05 Feb 2017 07:31:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=decampo-org.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=bUBb6Ox+0wU/FLFpq1VtMV7IUVPTF+2Oylj6xLeSibA=; b=r4UOQe6lmvOTEY1Bim1iwHJ8YqH60swCWWS3uBKzgcfUhKWpBdSZctLUrbn9FsC94v CUhXYK2X16gGnt2PrBRLhMOCawVR2lKUUm9myjQVPAZ31eQWcGo0+NgyoOCUaostblEf KvsASX/czZMYM81+235s2Zwn8WqSvdVzLEwDpevbhrcoJewILkWTEUtz6ihmdPUmqk3P sMqhsIP8E18MVSYYDFjToAHkc4aplpn3c+pkoYnvQqZkMM2VvD0sq87Go9SAml/utaSZ patHtbtQb7aH70GCj3boGa6leVfDW40Enwb9ORI4Q8EQdk+YRLUEoOJj6GgcMjOvjj9p BsVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=bUBb6Ox+0wU/FLFpq1VtMV7IUVPTF+2Oylj6xLeSibA=; b=AiGr27SgiyttaJcxnkZ/H68Fpa3YZq3RtY2hdwSf2OEsn4WgThcqSnAcKYP3IYc9PI aPwJIHkBsdSJ0QWCbdYBlIAXLj+zvzfL1sVvHildXzgABIwYxPGgzR6QQCjSV/M8wN1u Ox5LdNxObo+trdzZM6/bqQqk+IAmq3WnnGVjnGf4ItFPoDXZKCZjNzaIrEdS+0cHOT11 S17HpLORArctq5HfsSWCEkXcSwTbKlqv5Umat8VyPSPJY1EqhXkY+E16h0i0UgGeAylN l4DketE+Q6titb+PDFUHQixpYi95cj3/Lh2Bbwkk5G+pA4llLkXHzo5vYh3QYkkIej0b PLvQ== X-Gm-Message-State: AMke39kDNFXjs6FqQQDL+TK/U1HSu03SnemRmzlPNwGoyeUrA4Rsn+5mYU/nkYADGFWeP4W7NxSRKCMWu2BW/w== X-Received: by 10.202.85.148 with SMTP id j142mr3180126oib.137.1486308693665; Sun, 05 Feb 2017 07:31:33 -0800 (PST) MIME-Version: 1.0 Received: by 10.74.75.131 with HTTP; Sun, 5 Feb 2017 07:31:33 -0800 (PST) X-Originating-IP: [72.228.81.86] In-Reply-To: References: From: Raymond DeCampo Date: Sun, 5 Feb 2017 10:31:33 -0500 Message-ID: Subject: Re: [exec] Misconcepting PumpStreamHandler's way of working with streams? To: Commons Users List Content-Type: multipart/alternative; boundary=001a113df284b687e20547ca35fa archived-at: Sun, 05 Feb 2017 15:31:40 -0000 --001a113df284b687e20547ca35fa Content-Type: text/plain; charset=UTF-8 Edgar, I didn't see anything obvious wrong with what you posted. If you can distill it down to a minimal self-contained example that reproduces the behavior I can take a closer look. On Sat, Feb 4, 2017 at 1:47 PM, Edgar H wrote: > I've been struggling with this problem for quite some time now as it's my > very first time doing an application related to streaming and I just can't > figure out why. Here's the problem... > > What I'm trying to achieve is to send a command's output as an input for > the next one, which is basically what the pipe operator does. As I knew > this couldn't be executed directly with Exec library from Apache Commons I > started looking for ways to solve this. I've seen quite a few examples of > similar things to this but none of them covers my situation: > > I have two Java applications separated, one is the main application and the > second one is initialized by the first one. This second applications sends > to the Standard Output bytes, which FFMPEG should receive. > > The code that I have so far is the following one... > > public void initStream(String path) { > File file = new File(path); > for (File s : file.listFiles()) { > if (s.getName().equals("ffmpeg.exe")) { > try { > > // Second app, supposedly, writes here. > PipedOutputStream output = new PipedOutputStream(); > > DefaultExecutor executor = new DefaultExecutor(); > //DefaultExecutor executorFFMPEG = new DefaultExecutor(); > executor.setWorkingDirectory(file); > //executor.setWorkingDirectory(file); > > CommandLine commandLine = new > CommandLine(s.getParentFile().getAbsolutePath()); > System.out.println("Path: " + commandLine.toString()); > > String executeMe = "java -jar streamer.jar"; > commandLine = CommandLine.parse(executeMe); > > System.out.println("[testing] streamer about to launch."); > executor.setStreamHandler(new PumpStreamHandler(output, > null)); > executor.execute(commandLine, new > DefaultExecuteResultHandler()); > System.out.println("[testing] streamer started."); > > PipedInputStream input = new PipedInputStream(); > output.connect(input); > > String feedMe = "ffmpeg"; // more attributes here > commandLine = CommandLine.parse(feedMe); > > System.out.println("[testing] ffmpeg about to launch."); > executor.setStreamHandler(new PumpStreamHandler(null, > null, input)); > executor.execute(commandLine, new > DefaultExecuteResultHandler()); > System.out.println("[testing] ffmpeg started."); > > } catch (IOException e) { > e.printStackTrace(); > } > } > }} > > And the code for the second application (the zone where I send data to > the stdout) is the following one. > > static OutputStream stdout = System.out; > > (more code and other things around here) > > try { > line = (TargetDataLine) mixer.getLine(info); > line.open(format); > > int bytesRead, CHUNK_SIZE = 4096; > byte[] data = new byte[line.getBufferSize() / 5]; > > line.start(); > > while (true) { > bytesRead = line.read(data, 0, CHUNK_SIZE); > stdout.write(data, 0, bytesRead); > stdout.flush(); > } > > } catch (LineUnavailableException ex) { > System.out.println("Line is unavailable."); > ex.printStackTrace(); > } > > At the moment, no communication seems to be made between both commands as > ffmpeg isn't receiving anything. > > Hope you guys can tell what I'm missing out, or if I'm incorrectly working > with the library thinking it works in a way when it works in another one. > --001a113df284b687e20547ca35fa--