Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8361509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:43:02+00:00 2026-06-09T11:43:02+00:00

Short : What is the best way to invoke a process from Java and

  • 0

Short: What is the best way to invoke a process from Java and have its output be consumed by a C++ function invoked via JNI.

Long: I am experimenting with a log reader application for Android. For that, I have to run the logcat command and parse its output. I have attempted this from Java, but the amount of memory allocations performed are such that not only makes the process utterly slow but it also clutters the very same log with lots of GC related entries.

For that reason, I have implemented all parsing related operations in C++. However, I can’t use the usual fork/exec idiom to invoke logcat from the C++ side as its not really supported by the NDK. Instead, I need to start the process from Java and somehow make its output accessible to the C++ code. Ideally I would use a pipe for this, but the redirectOutput methods from ProcessBuilder are not available on Android either.

The best solution I have come up with so far is to start the process redirecting its output to a temporary file (using logcat > tempfile), and have the C++ code read from that file. However, this is far from ideal. Is there a better way to have native code access the output of a process started from Java?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T11:43:03+00:00Added an answer on June 9, 2026 at 11:43 am

    Your premise is a bit mistaken: fork/exec() is no more “proper” on Android when accomplished from Java than when accomplished via the NDK – in both cases it works today, but is considered to be outside of the way Android apps are supposed to work.

    Reading the logs is another borderline case: as of JellyBean, you can only read your own (process or userid, not sure which) messages. There is an ADB command which can be used to enable a given app to read all logs as in previous releases, but that has to be issued from the ADB – it cannot be set up by an app.

    If you want to do literally what you have stated, regardless of the lack of necessity and impending limitation of utility, the thing to do would be to get knowledge of the file descriptors connecting to the child process into the native code. You may be able to pass it, or the native code may be able to discover it for itself, since all file descriptors are listed in /proc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have PCM samples in a short array. What is the best way to
Short version: I'm trying to determine the best way to track what the user
Does someone know a fast way to invoke shader processing via DirectX? Right now
SHORT VERSION: What is the best way of casting 5- as a number for
What is the best way of replacing a set of short tags in a
We have an ASMX web service which we invoke from our ASP.NET application using
Short version: What's the best way to stay on the same page to run
In short: what is the best way to design and implement a factory+plugin mechanism,
Long story short, I am looking for the best way to quickly and efficently
In pursuit of finding the best way to have a date displayed on a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.