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 8152543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:44:37+00:00 2026-06-06T15:44:37+00:00

I am trying to run a c++ executable from my Java web application. When

  • 0

I am trying to run a c++ executable from my Java web application. When I go the relevant page it executes the commands and runs the executable but does not produce any output.

Here is my code:

URL createWav = QRcodeController.class.getClassLoader().getResource("createWav");
log.info("The path of the c++ executable obtained: "+ createWav.getPath());
Process p1 = Runtime.getRuntime().exec("chmod 777 " + createWav.getPath());
p1.waitFor();
int exitVal=1;
try {
        Process p2 = Runtime.getRuntime().exec(createWav.getPath(), args);
        exitVal = p2.waitFor();
}
catch (Exception e)
{
    log.error(e.getStackTrace());
}
if(exitVal == 1)
    throw new Exception("Error in c++ program");

It does not throw any error so the c++ program runs fine but it does not produce the file it is supposed to. When I run the same command from the command line in the same machine it works perfectly producing the required file. I am not sure what I am doing wrong.

  • 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-06T15:44:38+00:00Added an answer on June 6, 2026 at 3:44 pm

    The C++ program is writing its output to a pipe, not the standard output of the Java program. Use Process.getOutputStream() to access that stream or, with Java 1.7, employ a ProcessBuilder where you can use redirectOutput like this:

    pb.redirectOutput(ProcessBuilder.Redirect.INHERIT)
    

    In case your C++ program might write things to its standard error stream, you should probably deal with that in the same way.

    Also note that leaving either of these streams connected to a pipe and not reading from that pipe might cause your application to block on output if the buffer associated with the pipe becomes full. To simply ignore output, you’d have to explicitely redirect it to /dev/null. That’s not your aim just now, but it might be in a different situation.

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

Sidebar

Related Questions

I am trying to run a 64 bit executable (java.exe) from our 32-bit .NET
I am trying to run .exe file, which uses another not executable files from
I have an executable file (ffmpeg) that I'm trying to run with a Java
I've been trying to create an executable file from a Makefile to run a
I am trying to run the following ruby code from IRB but am unable
I am trying to run an executable from a c++ program. I have looked
I need help in trying to execute an executable from my C# application. Suppose
I'm trying to run an executable from memory such as outlined in this article.
I'm trying to run an external executable, but apparently it needs elevation. The code
I was originally trying to run an executable ( tftpd32.exe ) from Expect with

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.